Hiding menus in the WordPress Dashboard

      Comments Off on Hiding menus in the WordPress Dashboard

If you’ve been working for a while on your website you might end up with a clutter of menus on your left hand side of the Dashboard. Some of these entries are quite useful, but there are also some that are just taking up precious space. Lucky for us WordPress comes shipped with a nifty function that allows us to hide unwanted menu items from the Dashboard. In order to use this you can include this function in either a plugin, or inside your themes functions.php.

Setting up the required function and action

In order to get this going we’ll need to build a function first that will actually hide these menu items we don’t want. We can use the function remove_menu_page() to achieve this. In this specific case I want to hide the Media, Appearance and Tools pages. For this we can call the aforementioned function three times in a row, just like this:

function clean_menus() {
    remove_menu_page( 'upload.php' );                 //Media
    remove_menu_page( 'themes.php' );                 //Appearance
    remove_menu_page( 'tools.php' );                  //Tools

What we are doing here is creating a new function named clean_menus(). This function contains all the required calls to (in this case) remove_menu_page(). If you want to hide other pages, make sure to check the documentation at WordPress.org for their correct paths. All default WordPress pages are listed there. You can also use this function to hide menu items generated by your theme and plugins. All that’s left is to actually run this function. We use add_action() to attach it to the right hook:

add_action( 'admin_menu', 'clean_menus' );

As you can see there is not much to it. This way you can clean up unused items from your Dashboard, making it all shiny and pretty again. You might even combine this with other functions, such as current_user_can() to filter out specific items for specific users.