How to remove top level menu items in WordPress

You probably already know that WordPress is highly customizable. If you know how to code or at least find the right plugins, you can transform your backend as well as the frontend and showcase a unique website to your visitors and your authors as well. We have already shown you some of the best plugins for editing WordPress mobile menus and how to rearrange menu items by using a simple plugin. In today’s article, we will show you a simple code which will allow you to remove top level menu items from your WordPress admin pages.

The code you can find below will remove all top level menu items to all users instead of admins. Before you continue, you should know that this snippet only removes the menu items but that those items will still be available to anyone who knows the correct path to a settings page. If you want to completely restrict access to certain menu pages, you will have to change the user capabilities.

Remove top level menu items:

  1. Open your functions.php file
  2. Copy and paste the following code:
  3. if (!current_user_can( 'manage_options' )) {
    add_action( 'admin_menu', 'my_remove_menus', 999 );
    }
    function my_remove_menus() {
    remove_menu_page( 'index.php' );                  //Dashboard
    remove_menu_page( 'edit.php' );                   //Posts
    remove_menu_page( 'upload.php' );                 //Media
    remove_menu_page( 'edit.php?post_type=page' );    //Pages
    remove_menu_page( 'edit-comments.php' );          //Comments
    remove_menu_page( 'themes.php' );                 //Appearance
    remove_menu_page( 'plugins.php' );                //Plugins
    remove_menu_page( 'users.php' );                  //Users
    remove_menu_page( 'tools.php' );                  //Tools
    remove_menu_page( 'options-general.php' );        //Settings
    }
  4. Save changes

As this code removes all of the top levels menus which you probably don’t want to do, feel free to modify the code to your needs. Each “remove_menu_page” line is in charge of removing one page (which is described in the brackets as well as in the comment beside the line of code). Simply add or remove a page you want to be absent from your menu and save changes one more time.

Now that you have learned how to remove top level pages from the menu, you might want to remove only some of the subpages which are located under the top level ones. If that’s the case, see how to remove subpages from your WordPress menu.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

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