
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!
21 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.
Hey Danny B,
When im pasting your code, it won’t work, and i remembered the PHP start and close tags. Its like it echos the 3-4 end lines… =/
Is it just me?
Please help me out, btw nice site!
Thank you for this. Very nice to block certain things for clients when you setup a wordpress site for them.
I am having the same issue as Phillip Lind.
Seems to be an issue with the syntax of
if(in_array($value[0] != NULL?$value[0]:”" , $restricted)){unset($menu[key($menu)]);}I have tried removing every combination (I think) of the characters :”” , as I assume the issue is here. I can get the syntax highlighting to be correct but cant actually get the script to run.
Reply or no reply, thanks for this code, will come in handy
Is there a way to do this on a plugin-by-plugin basis?
Meaning..I want to only give clients access to certain plugins?
I can do this manually by changing the access level, but that is a pain to do and manage over time.
Any plugin suggestions?
Most of the management ones out there (Role Scope, Hide Admin Menus, etc.) only handle the core top-level options and not the secondary ones.
Seems like an open opportunity for WordPress to implement into the core or someone to make a solid plugin that does this.
Sweet! It worked. Need to check on the single quotes when doing a direct copy and paste in the functions.php before saving; just a 2 cents if anyone got an error upon trying.
This works well and I’ve been using this for awhile to get rid of menus I don’t want my clients messing with. However, I came across a problem today regarding the W3 Total Cache plugin. I upgraded it to the latest version (0.9.1) and it created its own separate menu tab in the dashboard called “Performance”. Normally, I’d just add ” __(‘Performance’)” and it would get rid of it but this one seems stubborn to stay. Any ideas?
I looked through TotalCache.php and found this line. Don’t know how relevant it is but I thought it would help someone figure out how to get rid of the menu.
add_menu_page(‘Performance’, ‘Performance’, ‘manage_options’, ‘w3tc_general’, ”, plugins_url(‘w3-total-cache/inc/images/logo_small.png’));
I would like to remove a submenu, whatever it was, form wordpress or a plugin, how can I do this?
thanks
Trackbacks: