Here is the code you need to display the most recent 5 posts:
Category: WordPress Backend
Force Perfect JPG Images
WordPress doesn’t use 100% quality for images served on the website, to conserve space and bandwidth. add_filter( ‘jpeg_quality’, ‘smashing_jpeg_quality’ ); function smashing_jpeg_quality() { return 100; } WordPress uses a default quality of 90%. This is fine in most cases; if top-notch image quality is a must on your website (for a portfolio, photography, etc.), modifying […]
Replace Built-In Scripts By Deregistering Them
If you live on the bleeding edge, you can use versions of scripts other than the built-in ones. Using a newer jQuery version is common (though not necessarily good) practice, which can be done in the following way. function my_scripts_method() { wp_deregister_script( ‘jquery’ ); wp_register_script( ‘jquery’, get_template_directory_uri() . ‘/js/jquery-new.js’); wp_enqueue_script( ‘jquery’ ); } add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’); […]
Kitchen Sink
Add Link to WordPress “All-Settings”
As we’ve explained before, WordPress makes it easy to view and edit your blog settings from the Admin area. Thanks to a file named options.php, WordPress will display all of your database settings and enable you to edit a majority of them. To view this page, you need to log in as Admin and enter […]
Get Role
/*———————————————————————————–*/ /* GET role /*———————————————————————————–*/ function get_user_role() { global $current_user; $user_roles = $current_user->roles; $user_role = array_shift($user_roles); return $user_role; }
Another Way to Change the “Howdy” message to “Welcome”
/*************************************************************** * Change Howdy to Welcome ***************************************************************/ function change_howdy($translated, $text, $domain) { if (!is_admin() || ‘default’ != $domain) return $translated; if (false !== strpos($translated, ‘Howdy’)) return str_replace(‘Howdy’, ‘Welcome’, $translated); return $translated; add_filter(‘gettext’, ‘change_howdy’, 10, 3);
Changing “Posts” menu name in admin (e.g. “Articles”)
// hook the translation filters add_filter(‘gettext’,’change_post_to_article’); add_filter(‘ngettext’,’change_post_to_article’); function change_post_to_article( $translated ) { $translated = str_ireplace(‘Post’,’Article’,$translated );// ireplace is PHP5 only return $translated; } Credits to smashingmagazine.com
Remove WordPress Admin Bar Menu Items
function dashboard_tweaks() { global $wp_admin_bar; $wp_admin_bar->remove_menu(‘wp-logo’); $wp_admin_bar->remove_menu(‘about’); $wp_admin_bar->remove_menu(‘wporg’); $wp_admin_bar->remove_menu(‘documentation’); $wp_admin_bar->remove_menu(‘support-forums’); $wp_admin_bar->remove_menu(‘feedback’); $wp_admin_bar->remove_menu(‘view-site’); } add_action( ‘wp_before_admin_bar_render’, ‘dashboard_tweaks’ ); Reference: http://pastebin.com/Wrk0JPxw
Remove Admin Backend Menus for all users, except User #1 (usually the first Admin)
/*———————————————————————————–*/ /* Restrict access /*———————————————————————————–*/ function remove_menus () { global $menu; $user = wp_get_current_user(); if ($user->ID!=1) { // Is not administrator, $restricted = array(__(‘Dashboard’), __(‘Posts’), __(‘Media’), __(‘Links’), __(‘Pages’), __(‘Appearance’), __(‘Tools’), __(‘Users’), __(‘Settings’), __(‘Comments’), __(‘Plugins’)); end ($menu); while (prev($menu)){ $value = explode(‘ ‘,$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:”” , $restricted)){unset($menu[key($menu)]);} } } } add_action(‘admin_menu’, ‘remove_menus’);