I often get asked by users how to remove menu pages from the WordPress admin. WordPress actually makes this task extremely easy. In this tutorial, I’ll cover the remove_menu_page() and remove_submenu_page() functions, which were added in WordPress 3.1.
Note that this tutorial only shows you how to remove items from the WordPress administration menu. It does not block access to menu pages via direct URL. It’s great for hiding things, but it should not be used as a way to secure specific admin screens. For that, you’ll need to work with the capability system.
Setup
The first thing you need to decide is where you’re putting the code. I’ll assume you’re either dropping this in your theme’s functions.php file or one of your plugin files.
The next step is to create your custom function to remove menus and add it to the admin_menu hook. Use a priority of 999 to make sure your code runs last. Your code should look like the following:
add_action( 'admin_menu', 'my_remove_menus', 999 );
function my_remove_menus() {
/* Use remove_menu_page() and remove_submenu_page() here. */
}
Removing top-level menu pages
To remove top-level menus from the admin, you’ll use the remove_menu_page() function. This function takes in a single parameter of $menu_slug. This is a unique slug that defines the menu.
remove_menu_page( $menu_slug );
Suppose you wanted to remove the “Links” section from the WordPress admin because you simply don’t want to use it. To do this, you need its menu slug, which is link-manager.php. Now, plug it into your setup function, which should look like the following code.
add_action( 'admin_menu', 'my_remove_menus', 999 );
function my_remove_menus() {
remove_menu_page( 'link-manager.php' );
}
Pretty simple, right? You just plug in a few lines of code.
Removing sub-menu pages
Removing sub-menu pages is nearly as simple as removing top-level menu pages. WordPress has you covered with its remove_submenu_page() function. The difference with it is that it takes in two parameters: $parent_slug and $menu_slug.
remove_submenu_page( $parent_slug, $menu_slug );
One of my favorite sub-menu pages to remove for my sites is the theme editor because I never edit themes on a live site. Everything is always coded on a development install in a text editor, so this menu item just takes up valuable space. To remove it, I need the parent menu slug (themes.php) and the theme editor menu slug (theme-editor.php). Then, I just plug the code into my custom function like so:
add_action( 'admin_menu', 'my_remove_menus', 999 );
function my_remove_menus() {
remove_submenu_page( 'themes.php', 'theme-editor.php' );
}
How to find menu page slugs
So you know how to remove menu and sub-menu pages from the admin. Using the functions is easy, but you actually have to know the menu slugs to remove them.
To find a menu page slug, simply click on a menu item in the WordPress admin and look at the address bar in your browser. You should see a value similar to the following.
http://localhost/wp-admin/menu-slug.php
The menu-slug.php is the unique menu page slug for an admin screen. You’ll use that in conjunction with the functionality you’ve already learned.
This is EXACTLY what I needed for what I am working on literally this second for a client. Much appreciated for the timeliness!
Glad I could be of help.
I can see where this would come in handy.
I use it mostly in my mission to clean up the WordPress admin. There are some things I simply have no use for. It can also be good for clients when you need to simplify things for them.
How about the menu items generated from plugins such as Contact Form 7 which use slug/urls such as: admin.php?page=wpcf7 or even, options-general.php?page=contact-form-captcha/contact-form-captcha.php
I assume Contact Form 7 is adding a top-level menu, so its slug is
wpcf7. As for the captcha page, it looks like its menu slug iscontact-form-captcha/contact-form-captcha.php(really weird if this is a sub-menu page) and its parent slug isoptions-general.php.Yep, remove_menu_page( ‘wpcf7′); removed the Contact Form 7 top level menu and remove_submenu_page( ‘options-general.php’, ‘contact-form-captcha/contact-form-captcha.php’ ); removed the captcha subpage — thanks!
Kinda wish there were almost less options for these menus to get dumped into the admin. Oh well – price we pay for flexibility.
I love the capability, it seems like a nice way to keep clients out of trouble. I see one small issue. On the actual example for removing a “sub-menu page”, you have
remove_menu_page ( ‘themes.php’, ‘theme-editor.php’ );
it should be
remove_submenu_page ( ‘themes.php’, ‘theme-editor.php’ );
Thank you for great instructive posts.
Thanks for letting me know. Post updated.
This is much nicer than the old method of filtering the menu array. Thanks for posting this.
I don’t even want to think about the old days when we had to do that.
This is very useful for cleaning up the admin area. To take it a little further, how can we check for user level before removing menu items? For example, to remove dashboard for subscribers.
Thanks Justin for the post.
Works fine locally.
Am having a problem getting this to work on live server, seeing Internal Server Error 500 whenever I try to access Admin screens. Not sure what this could be caused by. I’ve stripped everything else out of functions.php, and checked it’s not a typo. I’ve copied your above code as is:
add_action( ‘admin_menu’, ‘devpress_remove_menus’, 999 );
function devpress_remove_menus() {
remove_menu_page( ‘link-manager.php’ );
}
If I comment out remove_menu_page the Admin screens work.
Would be very grateful for any ideas. Thanks.
Sorted – of course it would help if it was latest version – doh.
what about the tags menu ?
the slug is the same for tags and categories menu.
Waon very awesome trick, easily implement in less time
Thankx
Good to know. The WordPress sidebar nav has really gotten out of hand for me with 7 custom post types, plus a dozen plugins that all want their place in the sidebar. Any pixels I can get back is worth it.
Can you advise how to remove a sub-menu from the admin bar at the top? I am trying to remove two of the selections from the Add New menu utilizing
But it does not seem to work for submenus. Top-level menus I can remove without problem.
Is there any way to hide a certain page from the admin panel? For example this: /wp-admin/post.php?post=123
Great article. Thanks. This will come in handy with limiting what pages clients will see.
Awesome, i would love to see how to add custom menus too.
Menu items disabled this way are still accessible via direct typing in address bar. They’re not visible in admin left menu but if you type:
http://yourdomain.com/wp-admin/theme-editor.php
you can still get the editor.
Is there any way to disable/hide theme/plugin editor from direct address access?
I was wondering the same thing as @elixoid . Just removing the page from the menu is definitely nice, but it doesn’t prevent users from still accessing the page itself and mucking with options we would rather they not. I had toyed around with the “get_current_screen()” function, but it is difficult to determine the “base”, “id”, or “action” attribute values for various admin pages. For example, I tried the following to disable the “Add User” admin page for a networked site:
# in functions.php file
But this will become lengthy with many other pages, and takes an initial var_dump of “$info” on each page I want blocked so I can check what the values are. Is this the best way to go about this, or is there a better way?
Thanks for posting this. Most articles are just a code dump with no explanation.
Does anyone know how to MOVE submenu items? Or maybe an article link that shows how to do this? It drives me up the wall that every plugin handles this differently; some devs put their admin menus under Tools, some put it under Plugins, some set up their own menus (Contact Form 7, for example). I assume it would be some combination of ‘remove_submenu_page’ and ‘add_submenu_page’ but was looking for some pointers. Thx
From this article, is it safe to replace:
with:
?
I had a number of items (non-standard WP pages) not work with admin_menu, that I could suddenly hide with
admin_init, like:remove_submenu_page( 'users.php', 'user-role-editor.php' );No, it’s not safe to assume that. Most likely, the issue you’re running into is that your plugin authors aren’t using the correct hook to load their menus. For your particular example, I can almost guarantee it.
My recommendation would be to talk to the specific plugin author in question and ask if they’ll update their plugin to use the correct hook. If they don’t understand, feel free to refer them to me for a more thorough explanation.
Hi,
This works for most menu items but not all and i can’t work out why? It’s certain plugins and themes. for example I have a theme framework which give the an admin page at
/admin.php?page=sitemile-frameworkI can’t for the life of me work out what the slug should be. This doesn’t work:
but I found the code that is creating the item and it is:
So why is my code not working? Can anyone shed some light?
Thanks for the post
I would look into it, but your theme is in violation of the WordPress license. I recommend getting a different theme.
Wow, I search and use many codes for remove admin menus but not work your code snipt work like charm.
Thanks for you help.
not work in wp 3.0 ?
What about other plugins instead of Contact Form 7?
How can I find the slugs from top level menu and submenu of them?
Thanks
Thanks for the great post.
I’ve come a bit unstuck though, wondered if you could help.
I have a plugin with an admin page whose capability is set to “administrator”, I need to change this to something more useful.
I can’t edit the plugin directly so I thought that by removing the submenu page in functions.php and then re-adding it with the appropriate capability type it would solve the problem.
The menu item is now visible to the roles that I want but accessing the page still gives the “insufficient permissions” error.
What am I missing?
Thank you..!!
Really nice post.. It’s Work..
I’d like to improve my knowledge in wordpress
What about removing the Pods Admin from the backend? Nothing works here
Hi and thanks, it really help me.
What about to hide some non standard Wordpress submenu created by plugin like Background manager, or upPrev, the submenu links are :
…./wp-admin/themes.php?page=xYzc4O
or
…/wp-admin/themes.php?page=upprev/admin/index.php
thanks
Thanks, you explained it very well. I assumed you would be able to just put the menu names into the function.