Codeable info

Removing WordPress Admin Menus

Posted on by in WordPress Tutorials

When deploying WordPress sites for clients, it can be extremely useful to customize aspects of the WordPress admin area. For users who are not familiar with WordPress, some aspects of the admin area can be confusing, especially if they are not being directly utilized by the client. For example, not all users need a Links section for their site (perhaps less is more if you are designing a site for a client using WordPress). So here’s a quick tip for removing menu items from the main admin navigation.

Simply paste this into your functions.php:

// function to remove the Links menu item
function remove_menus()
{
	// setup the global menu variable
	global $menu;
	// this is an array of the menu item names we wish to remove
	$restricted = array( __('Links'),__('Tools'),__('Settings'),__('Comments'));
	end ($menu);
 
	while (prev($menu))
	{
		$value = explode(' ',$menu[key($menu)][0]);
 
		if(in_array($value[0] != NULL?$value[0]:"" , $restricted))
		{
			unset($menu[key($menu)]);
		}
	}
}
// hook into the action that creates the menu
add_action('admin_menu', 'remove_menus');

This code will remove the Links, Tools, Settings, and Comments menu items. Simply add all the menu names you wish to remove to this part of the code above:

$restricted = array( __('Links'),__('Tools'),__('Settings'),__('Comments'));

So what would it look like if you wanted to remove the Tools, Comments, Appearance, Plugins, and Settings menus? The complete code is this:

// function to remove the Links menu item
function remove_menus()
{
	// setup the global menu variable
	global $menu;
	// this is an array of the menu item names we wish to remove
	$restricted = array( __('Tools'),__('Comments'),__('Appearance'),__('Plugins'),__('Settings'));
	end ($menu);
 
	while (prev($menu))
	{
		$value = explode(' ',$menu[key($menu)][0]);
 
		if(in_array($value[0] != NULL?$value[0]:"" , $restricted))
		{
			unset($menu[key($menu)]);
		}
	}
}
// hook into the action that creates the menu
add_action('admin_menu', 'remove_menus');

I hope you found this article useful. If you are unsure about anything please let me know :)

Pippin

)
Codeable info

Comments (5)

Comment by site value says:

WordPress is a fantastic blogging tool and publishing platform, but is it optimised out of the box for Search Engine Optimisation (SEO)? Well, despite the fact that the search engines tend to love websites built on the WordPress platform, it isn’t particularly well optimised with a default installation. In the default WordPress installation, it does not include meta tags such as meta description and meta keywords. If you want to supply search engines with specific information, relevant to your websites pages, you are going to have to add the meta tag data yourself.

Comment by Jeff Carter says:

What about removing menu items added by themes and plugins? I’m trying this, but apparently the name I’m using for the certain menu item is just a menu title, not a menu name. How to you find the menu name?

Comment by Robert McLeod says:

Thanks! This is exactly what I was looking for :)

Comment by Jatinder Bhambri says:

kindly mention where this function is to be declared ,, and from where i have to call that function ,,,

Comment by Pippin Williamson says:

Paste the function into the functions.php file inside your theme directory. You do not need to call the function from anywhere, just include it in functions.php.

Codeable info