menu_items

Cleaning Up WordPress Admin Menus

As a WordPress developer, I often find myself tasked with building very specific WP themes. So specific in fact, that I end up leaving out a lot of the default functionality. The problem is, I want the client to have a seamless experience while dealing with the back-end of their site. I don’t want them wondering what the Comments tab does, or why the Posts tab brings them to an empty list, because maybe their site didn’t require those options.

So, what to do? Well, hide them. Hiding unused menu tabs is a quick and easy way to de-clutter the back-end of your WordPress site. WordPress 3.1.0 introduced two new ways of doing this: remove_menu_page and remove_submenu_page.

The example below shows how you would remove the Comments menu item, by pasting this code in your functions.php file:

	add_action( 'admin_menu', 'my_remove_menu_pages' );
	function my_remove_menu_pages() {
		// the parameter is the slug of the menu item to be removed
		remove_menu_page(‘edit-comments.php’);
        }

But what if you want to remove more than just the comments? That the easy part, just call remove_menu_page() again, inside the function, passing the menu item’s slug as the main parameter.

That works great for top-level menu items, but what if we want to remove sub-menu items? That’s where remove_submenu_page() comes in. The example below shows how you would remove the Editor sub-menu item, by pasting this code in your functions.php file:

add_action( 'admin_menu', 'my_remove_sub_menu_pages' );
	function my_ remove_sub _menu_pages() {
		// the first parameter is the slug of the top menu item to be removed
		// the second parameter is the slug of the sub-menu item
		remove_submenu_page( 'themes.php', 'theme-editor.php' );
        }

Again, you can call this as many times as you’d like, to remove even more sub-menu items.

Leave a Reply

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

Sign Up

Sign Up for our newsletter here. We’ll send you cool WordPress tips, tricks, and news. No spam, we promise.

  • This field is for validation purposes and should be left unchanged.