X

How To Disable Top-Level Menus From the Admin Panel

Snippets by IsItWP

Are you looking for a way to disable top-level menus from the admin panel? These snippets disable top-level menus, like the Comments menu, from the main menu in the admin panel.

Instructions:

Add one of the following snippets to your theme’s functions.php file or in a site-specific plugin:

  • This snippet disables top-level menus using the menu ID. Menu IDs can be found in the wp-admin/menu.php WordPress file. Edit the menus IDs in lines 3 and 4, or add more similar lines, to change which menus are disabled.
    function remove_menu_items() {
      global $menu;
         unset($menu[15]); // Removes 'Links'.
         unset($menu[25]); // Removes 'Comments'.
    }
    add_action('admin_menu', 'remove_menu_items');
    
  • This snippet disables top-level menus using the menu name instead of the menu ID. Edit the menus names in line 3, or add more array items, to change which menus are disabled.
    function remove_menu_items() {
    global $menu;
      $restricted = array(__('Links'), __('Comments'));
      end ($menu);
      while (prev($menu)){
      $value = explode(' ',$menu[key($menu)][0]);
      if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
    	}
    }
    add_action('admin_menu', 'remove_menu_items');
    

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: How to Install Google Analytics on Your WordPress Site.

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!
[63% OFF Today!]
[63% OFF Today!]
[60% OFF Today!]
[60% OFF Today!]
[50% OFF Today!]
[50% OFF Today!]