Removing the Top Menu Links from WordPress Bar

Published by John on June 15, 2012 Under Wordpress

This is a quick follow up to my previous post on changing, restricting, and renaming the wordpress admin menus. It doesn’t go into as much detail, but between the two of them, most menu items can be removed for specific user types.

This can be pasted into your functions.php file and removes the top right menu items, including the quick-links, like the ‘Edit My Profile’ and ‘Log Out’ links, in addition to the left hand side items.

Please read notes below before using this in a non-development website.

if (!current_user_can('administrator')){
 
        show_admin_bar(false);
        add_action( 'wp_before_admin_bar_render', 'kcr_remove_top_admin_menus' );

 
}
function kcr_remove_top_admin_menus(){
	global $wp_admin_bar;
	
	//For Debugging, uncomment below
	//print_r($wp_admin_bar); die;
	
	//Remove Quick Links, including logout, top right
	$wp_admin_bar->remove_menu('my-account'); 
	$wp_admin_bar->remove_menu('my-account-with-avatar'); 
	
	//Remove Left Hand Side WordPress Logo
	$wp_admin_bar->remove_menu('wp-logo'); 
	
	//Remove Left Hand Side Link Back to Website
	$wp_admin_bar->remove_menu('site-name'); 	
	
	//Additional Options, might not be correct! 
	
	//$wp_admin_bar->remove_menu('about'); 	
	//$wp_admin_bar->remove_menu('edit-profile'); 
	//$wp_admin_bar->remove_menu('logout'); 
	//$wp_admin_bar->remove_menu('dashboard');
	//$wp_admin_bar->remove_menu('user-info');
	//$wp_admin_bar->remove_menu('user-actions');
	
	
	//$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('site-name'); 
	//$wp_admin_bar->remove_menu('view-site'); 
	//$wp_admin_bar->remove_menu('top-secondary'); 
	//$wp_admin_bar->remove_menu('wp-logo-external'); 
	
} 

Before Using This Code

As with the other plugin, this does not disable any menu items.. It only hides them, so you would not want to rely on it for security.

The commented items may not be correct, removing the current items, effectively remove all elements from the top bar for subscribers. Some of the commented out items may be incorrect.

It would also be wise to tweak the bar, so that your company logo and/or design is used. However, the user can make these changes.


No Comments |

Add a Comment