
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!
14 Responses
Would minimizing the menus be the same thing? Or do they still load at startup but aren’t displayed?
Great tricks to remove menus in the dashboard. Thanks.
But one thing i need your help. How can i create most commenter list and sort by number of comments without a plugin?
Help me please.
That’s great thanks – It will be nice to remove access to the Appearance and Plugins areas for my customers – should make my life easier
Can this be changed to only apply to certain roles or am I misunderstanding its use?
Now, i can remove user menu in dashboard… Great Thanks
I’ve been looking for this info…thanks for the post
Does it remove them for admin user as well? Would be great to remove them only for editor or other user roles specifically!
Thanks for this!
For those asking about how you could hide items for certain roles but keep them for admins, you could extend this with the following
function remove_menus () {
global $menu;
if( (current_user_can(‘install_themes’)) ) { $restricted = array(__(‘Links’)); } // check if admin and hide these for admins
else { $restricted = array(__(‘Links’), __(‘Tools’)); } // hide these for other roles
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’);
The above is useful because we get a lot of client wondering about the Turbo option under the Tools menu and it’s easier just to remove it but of course, when you’re logged in as an admin the Tools menu is super important with options like Import and Export etc. This will let you hide options
I LOVE YOU! I was hacking my wordpress core files and now i found this! It’s super, I just wanted to let you know I love you… ps! this whole user management is fucked up in wordpress, admin should be able to create custom user roles and choose what to hide etc.
great find!
i wonder how would i under the appearance menu only show the widget option?
this is something ive wanted to do for some time it would be great if i can give access to editors the widget page only and not the theme.
Thanks @Danny B. your solution was just what I was looking for, still a noobie in wordpress, but will be giving back once I am more familiar with it.
Trackbacks: