Tutorial: Remove Unneeded Admin Menus in the WordPress Dashboard

Relating to the last post, sometimes it’s helpful to clean up WordPress menus and submenus – such as Links, Appearance, and Tools – that aren’t being used. This simplifies the Dashboard, and minimizes the possibility of a website owner breaking their WordPress site by say, changing their active theme.

There’s an oft-duplicated post floating around the Internet that suggests updating the $global variable. Yikes! There’s a better way… 

The cleaner thing: a built in WordPress function just for this!

WordPress 3.1 actually builds in a way to remove admin menus.

Take a look at the code below. In remove_menu_page, the argument is the name of the page that displays that menu. This is really easy to find – just go to your editor, hover over the menu title (the link with an icon), and see what the file is named. That’s the argument.

Use remove_submenu_page to remove submenu items – such as “themes”, under Appearance. I usually don’t want to remove the entire Appearance menu, to give the client access to widgets, so it’s best to just remove “Themes” and “Editor”.

For remove_submenu_page, the first argument is the filename of the parent menu. We can find this (in most browsers) by hovering over “Appearance”, and seeing the file that that links to. For Appearance, it’s themes.php. The second argument – you guessed it! – is just the file name of the child menu item. For “Themes”, it’s also themes.php. For “Editor”, it’s theme-editor.php. Pretty easy.

Finally, hook these items into the admin_menu and network_admin_menu actions. Voila!

Here’s an example of hiding certain administrative pages in the site administration Dashboard. This is for single-site installs (this is most sites), and for the site administration side multisite installs.

function remove_menus () {
   remove_menu_page('plugins.php');   //Plugins
   remove_menu_page('users.php');   //Users
   remove_menu_page('options-general.php');   //Options
   remove_menu_page('wpcf7');   //Contact Form 7
   remove_menu_page('upload.php');   //Media
   remove_menu_page('tools.php');   //Tools
   remove_menu_page('edit-comments.php');   //Comments
   remove_submenu_page('themes.php', 'themes.php');   //Themes
   remove_submenu_page('themes.php', 'nav-menus.php');   //Menus
}
add_action('admin_menu', 'remove_menus', 102);
									

Here’s an example of hiding certain administrative pages in the network admin Dashboard. This is the side of the network used to manage sites within your WordPress site. BuddyPress users, this is for you!

function network_remove_menus () {
   remove_menu_page('plugins.php');   //Plugins
   remove_menu_page('themes.php');   //Themes
   remove_menu_page('update-core.php');   //Updates
   remove_menu_page('settings.php');   //Settings
   remove_submenu_page('users.php', 'user-new.php');   //Add New User
}
add_action('network_admin_menu', 'network_remove_menus');
									

Now go forth and code wisely! :)

4 Responses to “Tutorial: Remove Unneeded Admin Menus in the WordPress Dashboard”

  1. Sam says:

    Hi there, Thanks for this, but I have some trouble to see the code (instead I just have “[codebox !]” and “[codebox 2]“).

  2. Miguel says:

    Hi Katie, I’m interested in removing admin menu items “the right way” but the [codebox 1] and [codebox 2] are not showing the code!
    Thanks in advance!

  3. Katie says:

    Ah, that’s the priority – in case you’re hooking multiple things to the same action. You can read more about the function in the WordPress Codex: http://codex.wordpress.org/Function_Reference/add_action

    Glad it helped! :)

  4. David says:

    Hi – thanks very much for this; what’s the ’102′ at the end of the add_action doing?

    D

Leave a Reply

You must be logged in to post a comment.