WP-Mix

A fresh mix of code snippets and tutorials

WordPress Remove Menu Item

Quick WordPress tutorial for you today. How to remove an unwanted item from the WordPress menu. You know, the main menu that you find on the left-hand side of the screen when logged into the WordPress Admin Area. If you have a menu item that you want to remove, this post shows an easy way of doing it.

For example, let’s say that you have a plugin that adds an item to the WP menu. But we really don’t want or need the menu item, as it only takes up precious screen space. So to remove the item from the menu:

  • Click on the menu link
  • Copy the URL of the page from the address bar of your browser
  • Paste the URL in a note or somewhere until needed later

Next, add the following code to your theme’s (or child theme’s) functions.php file, or add via simple plugin:

function shapeSpace_remove_menu_item() {
	remove_menu_page('menu-slug');	
}
add_action('admin_menu', 'shapeSpace_remove_menu_item', 999);

Next replace the menu slug menu-slug with the one that you copy/pasted previously into a note. For example, if your page URL looks like this:

https://example.com/wp-admin/edit.php?post_type=simple-pay

Then you would use edit.php?post_type=simple-pay as the menu slug. So the final code is thus:

function shapeSpace_remove_menu_item() {
	remove_menu_page('edit.php?post_type=simple-pay');
}
add_action('admin_menu', 'shapeSpace_remove_menu_item', 999);

Save changes and done. For more information about this technique, check out remove_menu_page() at WordPress.org.

Remove menu item for non-admins

As a bonus, here is how the above code would be modified to remove the menu item ONLY for non-admin users.

function shapeSpace_remove_menu_item() {
	if (!current_user_can('manage_options')) {
		remove_menu_page('edit.php?post_type=simple-pay');
	}
}
add_action('admin_menu', 'shapeSpace_remove_menu_item', 999);

Here we are using current_user_can() to check if the current user is not an administrator. If the user is not an admin user, the menu item will be removed. Bada bing bada boom.

Learn more

WordPress Themes In Depth