Post Pic

How to remove menus in WordPress dashboard

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

Jan 04 2010 09:49

Would minimizing the menus be the same thing? Or do they still load at startup but aren’t displayed?

Jan 04 2010 16:01

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.

Jan 05 2010 05:01

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 :)

Jan 06 2010 00:27

Can this be changed to only apply to certain roles or am I misunderstanding its use?

Jan 06 2010 05:04

Now, i can remove user menu in dashboard… Great Thanks

Jan 17 2010 18:56

I’ve been looking for this info…thanks for the post

Jan 21 2010 21:54

Does it remove them for admin user as well? Would be great to remove them only for editor or other user roles specifically!

Feb 01 2010 19:37

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

Feb 10 2010 03:12

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.

Feb 23 2010 00:47

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.

Feb 24 2010 03:05

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:

Leave a Comment

* Name, Email, Comment are Required