How to remove items from the WordPress Admin menu

How to remove items from the WordPress Admin menu

If you manage or build WordPress websites on behalf of your clients, you probably don’t want them to be able to access every last bit of the Admin interface.

You can restrict them to ‘Editor’ privileges, but sometimes you want them to have some of the benefits of being an Administrator, without necessarily giving them enough control to inadvertently bring their site crashing down.

Or, you may just want a bit of a tidy up, and remove some of the superfluous items from your admin menu without necessarily getting rid of the plugins that power them.

Thankfully, you can easily hide items from the WordPress Admin menu without much effort.

Find out the URLs you want to remove

To remove a link from the menu, you first need to know the URL of the page you want to remove.

All URLs within the WordPress admin section begin with your site’s domain name, then potentially a subdirectory, then finally /wp-admin/. For example:

https://rusticated.co/wp-admin/tools.php?page=regenerate-thumbnails
https://rusticated.co/wp-admin/options-permalink.php
https://rusticated.co/wp-admin/admin.php?page=wp_mailjet_options_campaigns_menu
https://rusticated.co/wp-admin/themes.php

The part after /wp-admin/ is the important part. So make a note of this part, for example:

tools.php?page=regenerate-thumbnails
options-permalink.php
admin.php?page=wp_mailjet_options_campaigns_menu
themes.php

Add some code to your functions.php file

Edit your theme’s functions.php file, and paste the following at the bottom. You’ll want to replace the page between the brackets with the filename of the menu item you got above:

function remove_menu_items(){
   remove_menu_page( 'themes.php' );
   remove_submenu_page( 'options-general.php','options-media.php' );
   remove_submenu_page( 'options-general.php','options-discussion.php' );
   remove_submenu_page( 'options-general.php', 'akismet-key-config' );
   remove_submenu_page( 'admin.php', 'wp_mailjet_options_campaigns_menu' );
}

add_action( 'admin_menu', 'remove_menu_items', 999 );
?>

If you’re removing a top-level menu item, then use remove_menu_page

Removing an item from a submenu

If you want to remove an item from a submenu, then you need to use remove_submenu_page

remove_submenu_page( 'options-general.php','options-discussion.php' );

For this, the first argument needs to be the URL of the top-level page. The second argument needs to be the URL of the item you want to remove.

So to remove the ‘Discussions’ link, which is under ‘Settings’, then you need to put the URL of the Settings (‘options-general.php’) as the first argument, and the URL of the Discussions page (‘options-discussion.php’) as the second argument.