Sometimes you run in to the requirement that certain admin menu items are hidden in the back end. It could be because only certain roles should see certain things or there are some items still being developed for the dev eyes only. Whatever the case, there is a really quick and easy way to hide them.

**One thing to note is that this method HIDES the menu items but does not make them inaccessible. That is outside of the scope of this blog post.**

The bread and butter of what we are trying to accomplish is the “admin_menu” action. You can hook in to that and start removing things:

Once inside the hook we will use the WordPress function “remove_menu_page“. This function only takes one parameter – the menu slug. There are 2 different types of slugs you can pass here. One is the name of the php page that is loaded, such as edit.php or tools.php:

This will effectively remove the corresponding menu item from the back end menu.

The other type of slug is the page name itself if there is no specific php file in the url. For instance, if you made a new custom admin page and the url was /wp-admin/admin.php?page=test_page, the code to hide that from the admin menu would be:

So to recap, you can hide the admin menu items either via the php script the page executes (edit.php) or by the page name itself if there is no php script in the url (‘test_page’).

Bonus:

A practical application for this is to hide any menu items that aren’t essential for more minor roles in the site. It’s not so much that other roles can’t access these pages so much as we want to keep it as clutter free for them as possible:

This just checks what role the current user is and hides menu items if they are not an administrator.