Skip Navigation
Madison, Wisconsin
Powderkeg Web Design
May 17, 2017

Hiding Items from the Wordpress Admin Menu

Nick
Nick
Hiding Items from the Wordpress Admin Menu

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:

add_action( 'admin_menu', 'pk_menu_page_removing',999 );
function pk_menu_page_removing() {
   //Remove Stuff Here
}

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:

add_action( 'admin_menu', 'pk_menu_page_removing',999 );
function pk_menu_page_removing() {
   remove_menu_page( 'edit.php' );
   remove_menu_page( '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:

add_action( 'admin_menu', 'pk_menu_page_removing',999 );
function pk_menu_page_removing() {
   remove_menu_page( 'test_page' );  
}

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:

add_action( 'admin_menu', 'pk_menu_page_removing',999 );
function pk_menu_page_removing() {
   $user = wp_get_current_user();
   if ( !in_array( 'administrator', (array) $user->roles ) ) {

      //Remove the stuff here

   }
}

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

Nick Kalscheur

Nick Kalscheur

Lead Developer