How to remove menu items from the WordPress admin area

 In Wordpress Admin

How to remove menu items from the WordPress admin area

The following code below will disable menus items on the WordPress admin area, this code snippet can be used on your theme’s functions.php or can just create a plugin for it.

Some consideration you should now before you use this code snippet:
1 – The menu items will not be visible for for all the users.
2 – This code snippet only removes the menu items the url for the menu items will stay available

add_action( ‘admin_menu’, ‘ns_menulinks_remove’ );
function ns_menulinks_remove() {
  remove_menu_page(‘index.php’); // This is for Dashboard
  remove_menu_page(‘edit.php’); // This is for Posts
  remove_menu_page(‘upload.php’); // This is for Media
  remove_menu_page(‘link-manager.php’); // This is for Links
  remove_menu_page(‘edit.php?post_type=page’); // This is for Pages
  remove_menu_page(‘edit-comments.php’); // This is for Comments
  remove_menu_page(‘themes.php’); // This is for Appearance
  remove_menu_page(‘plugins.php’); // This is for Plugins
  remove_menu_page(‘users.php’); //This is for Users
  remove_menu_page(‘tools.php’); // This is for Tools
  remove_menu_page(‘options-general.php’); // This is for Settings
}

Similar to the code above the code snippet below will disable the menu items on the WordPress admin area but only for a specific group of uses.

Some consideration you should now before you use this code snippet:
1 – Please change ‘array( 1, 2 )’ with the user ID that you want to allow to show the menu items
2 – This code snippet only removes the menu items the url for the menu items will stay availabl

add_action( 'admin_menu', 'ns_remove_menus', 999 );
  
function ns_remove_menus() {
    
  $ns_current_user_id = $current_user->ID; // get the user ID
    
  $ns_team_ids = array( 1, 2 );
    
  /* if current user id is not in the allowed array */
  if( ! in_array( $ns_current_user_id, $ns_team_ids ) ) {
      
    /* remove the menu items(s) */
    remove_menu_page(‘options-general.php’);    
  }
    
}

 

You may be interested to know in how to add admin menu item with admin page on WordPress, please click here to find out more.

Relevant reading here “WordPress Menu User Guide”

Recent Posts

Leave a Comment

Start typing and press Enter to search