DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

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!

Tags

27 Comments

  1. Great recipe. Thanks for pointing this out!

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

  3. 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!

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

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

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

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

  8. 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?

  9. 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.

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

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

  11. 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.

  12. 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.

  13. 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!

  14. LOL this comment is a hall of famer!

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

  16. 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/

  17. 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’ );
    }

  18. @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.

  19. 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?

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

  21. Great post and quite handy. Thanks for sharing!

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

    I’d like to improve my knowledge in wordpress

  23. It there any way to remove the whole menu?

  24. 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

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

  26. if you want remove dashboared just change css file “admin-bar”
    add “display:none;height:0px;”

  27. Nice one! I’m using easy-admin-menu plugin, http://wordpress.org/plugins/easy-admin-menu/ Allows you to reorder and hide items in the menu with a very easy interface, just drag and drop. Might be useful

Leave a Comment

Your email address will not be published. Required fields are marked *