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!

25 Responses

Jul 19 2011 02:59

Great recipe. Thanks for pointing this out!

Jul 19 2011 19:17

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’ );

Jul 27 2011 10:10

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!

Aug 22 2011 23:47

Nice trick, I’ve been wondering for a while if this was possible. Thanks for sharing.

Oct 08 2011 01:04

won’t work, must hooked to admin_head instead of admin_menu
code is wrong even on hungred’s post

Oct 28 2011 12:00

The code only hides the menus, doesn’t remove anything. URLs are still accessible.

Nov 17 2011 22:22

Cool snippet, works perfectly with the latest WP. Thanks!

Nov 23 2011 18:26

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?

Dec 16 2011 10:23

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.

Dec 18 2011 17:57

@Musti
use like this for media (and others) :

function remove_menu(){
remove_menu_page( ‘upload.php’ );
}
add_action( ‘admin_menu’, ‘remove_menu’, 999 );

Jan 02 2012 21:36

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.

Jan 22 2012 06:56

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.

Apr 06 2012 11:27

WP IS A SHIT!

AVOID THIS CRAP AND SAY HELLO TO FREEDOM!!!

WP IS THE MOST OVERERSTIMATED SOFWARE ACTUALLY AROUND.
CORE CODE IS A DAMN SHIT.
NO LANG SUPPORT
NOTHING IS USER FRIENDLY TOTALLY UNSAFE THATNK EVEN TO PLUGINS
IPER-HEAVYWEIGHT CORE DESIGNED WITH ABSOLUTELY NO PATTERNS
THE WORST TINYMCE VERSION EVER SEEN !!

NO GUYS WP IS THE WORST CRAP EVER SEEN ON THE WEB !!
PLEASE AVOID THIS SHIT YOUR LIFE WILL BE BETTER!

Apr 06 2012 12:51

LOL this comment is a hall of famer!

Apr 20 2012 07:56

Worked perfectly in WordPress 3.3.1 (4-20-2012)

Apr 26 2012 12:45

The method suggested by @Dave is the way to do it. This will ensure that WordPress takes care of removing the related stuff everywhere. Don’t just prevent the menu from showing, thats a lazy hack.

See
- http://codex.wordpress.org/Function_Reference/remove_cap
- http://www.garyc40.com/2010/04/ultimate-guide-to-roles-and-capabilities/

Apr 30 2012 23:23

As of WP version 3.1, you are provided with remove_menu_page() and remove_submenu_page() functions which is a lot easier to use. Just place something like this in your functions.php. (First parameter is the file name or parent file name of the page you want to remove, second parameter is the submenu you wish to remove.)

add_action( ‘admin_menu’, ‘my_remove_menu_pages’ );
function my_remove_menu_pages() {
remove_menu_page(‘edit.php’);
remove_menu_page(‘link-manager.php’);
remove_menu_page(‘themes.php’);
remove_menu_page(‘tools.php’);
remove_menu_page(‘upload.php’);
remove_menu_page(‘edit-comments.php’);
remove_menu_page(‘plugins.php’);
remove_submenu_page( ‘index.php’, ‘update-core.php’ );
remove_submenu_page( ‘options-general.php’, ‘options-media.php’ );
}

May 01 2012 21:49

@Guy: You can solve your problem by installing the plugin “Members”, which give you a submenu called “Role”. From there you can edit the capabilities of a role.
If you for instance change one of the roles by removing all “post” capabilities and make sure your users only have that role attached, they will not see the “Post” menu.

May 08 2012 05:21

Like Piet (28 Oct. 2011) already said, this removes nothing! it only hides the menu(s). Is there no way making it realy impossible to make the call for that specific menu we want to hide? If not than topic maybe better should be.. hide menu for …
Looking for option to prevent users can just make the call by adding by hand the specific url to menu which we admins want to remove for whatever reason.

Anyone?

Aug 16 2012 01:23

Hi!
The tag remain so that there is borders that appear.
How to remove the tag?

Sep 24 2012 21:32

Great post and quite handy. Thanks for sharing!

Nov 08 2012 11:42

Thank you, really nice post.. It’s Work..

I’d like to improve my knowledge in wordpress

Jan 23 2013 09:55

It there any way to remove the whole menu?

Apr 10 2013 18:30

Off-topic but… does anyone know how to hide specific posts / pages by ID in the Admin output? I’m guessing there’s a hook (which I’m just about to research) but thought I’d ask here just in case!

Thanks
Andy

Apr 20 2013 19:31

Just want to say THANK YOU!!! I was searching for a code to hide the dashboard from the authors and this worked perfect.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox