2

I want to hide some menus on admin panel: Appearance, Plugins, and Tools.

How to hide it without plugin?

And how can I un-hide them later easily?

  • I don't quite understand your question about un-hiding it. By removing the functions in my answer below, they should reappear. – iyrin Feb 13 '14 at 6:33
  • For all roles and capabilities? – Brad Dalton Feb 13 '14 at 10:58
4

You can do this with remove_menu_page. Add the appropriate menu slug in your functions.php of your theme or your plugin.

<?php remove_menu_page( $menu_slug ) ?>

Note that users can still access these menus using a direct link. If you intend to block a user from accessing a menu, you will have to set up a user role and make sure they don't have the relevant capabilities.

Here is a list of slug examples for the menus included in a clean WordPress install.

<?php
function 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  

}  
add_action( 'admin_menu', 'remove_menus' );  
?>
  • Does this also remove them from the admin bar on the front end for logged in users? – Brad Dalton Feb 13 '14 at 10:59
  • It does not appear to affect the admin bar. – iyrin Feb 13 '14 at 11:20
  • @RyanLoremIpsum: how if we only hide post->tag? (not all menu post) – Lena Queen Feb 13 '14 at 11:27
  • I don't understand the question. If you are asking about how to remove a sub menu item "Tags" from the "Posts" menu in the admin panel, this can be done with remove_submenu_page( $menu_slug, $submenu_slug );. Examples can be found at remove submenu page in WordPress codex. – iyrin Feb 13 '14 at 11:37
  • 1
    @RyanLoremIpsum that is additional question, and thanks for help – Lena Queen Feb 13 '14 at 15:53
1

can do it with remove_menu_page() try out these locations

Remove Menu Item in WordPress Admin Panel

Remove Unwanted Items from the WordPress Admin Sidebar

0

This is a nice chunk of code from Bill Erickson's Core Functionality plugin.

/**
 * Remove Menu Items
 * @since 1.0.0
 *
 * Remove unused menu items by adding them to the array.
 * See the commented list of menu items for reference.
 *
 */
function ni_remove_menus () {
    global $menu;

    // Example:
    //$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
    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', 'ni_remove_menus' );

Uncomment the restricted array and include the menu items you'd like to hide. The example contains all the menu items for reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.