
Happy 2010! To start this new year with a great WP recipe, I’m going to show you how you can easily remove menus in the WordPress dashboard. This can be really useful when building a WP site for a client.

Happy 2010! To start this new year with a great WP recipe, I’m going to show you how you can easily remove menus in the WordPress dashboard. This can be really useful when building a WP site for a client.
Simply paste the following code into the functions.php file of your theme. The following example will remove all menus named in the $restricted array.
function remove_menus () {
global $menu;
$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');
Thanks to hungred for this very useful trick! This recipes was previously featured in Cats Who Code 10 WordPress dashboard hacks article.
Enought said, I wish to all of you and your families a wonderful year 2010!
12 Responses
Great recipe. Thanks for pointing this out!
You can also go a little more granular using the remove_cap functionality:
Using the editor role specifically:
$editor = get_role(‘editor’);
$editor->remove_cap(‘publish_pages’);
Using global roles:
global $wp_roles;
$wp_roles->remove_cap( ‘editor’, ‘publish_pages’ );
Great snippet, thanks!
Can i use this code in any way to just remove a sub menu?
Remove Categories and Post Tage under the Posts menu for example?
Thanks!
Nice trick, I’ve been wondering for a while if this was possible. Thanks for sharing.
won’t work, must hooked to admin_head instead of admin_menu
code is wrong even on hungred’s post
The code only hides the menus, doesn’t remove anything. URLs are still accessible.
Cool snippet, works perfectly with the latest WP. Thanks!
Great!
Quick question. I have a custom post type called “listings”, but the label is “A to Z”.
I have tried:
$restricted = array(__(‘Listings’)…
and
$restricted = array(__(‘A to Z’)…
and it doesn’t work.
Any tips?
Hi, I am using the following function to remove some menus in the dashboard.
function remove_menus () {
global $menu;
$restricted = array(__(‘Dashboard’), __(‘Posts’), __(‘Updates’), __(‘Media’), __(‘Links’), __(‘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’);
Some of the menus in the array are removerd but Media and Comments menus aren´t. I couldn´t figure out what I am doing wrong.
Any help is very much apreciated.
@Musti
use like this for media (and others) :
function remove_menu(){
remove_menu_page( ‘upload.php’ );
}
add_action( ‘admin_menu’, ‘remove_menu’, 999 );
Hi,
I’m not a programmer, but can copy paste code into my functions.php. Here’s my question:
I have two custom post types:
1. Bio (For additional biographic fields)
2. Product (For product detail fields)
I want my admin menu to display the following according to roles:
1. Site Admin: Sees all menus
2. Free Subscriber: Sees only the standard WP Profile menu item in his dashboard.
3. Contributor, Author, Editor: Only see the Profile menu, the custom Bio menu, and the custom Product menu, and nothing else in their dashboard.
I’ve tried various approaches with snippets that work for a part here and other for another part. But I don’t know enough to get it all together.
Help would really be appreciated.
Thanks for the script it works fine but I need your help to customize the script please. How to apply this script to all users excluding or except userid 1 which would be the superadmin?
In the way the script will hide all the required menus except for the developer and designer.
Trackbacks: