Friday, May 8, 2020

Remove Admin Menu Items From WordPress Dashboard

https://isabelcastillo.com/remove-menu-items-wordpress-dashboard


This shows you how to remove WP-admin menu items from your WordPress dashboard.
First decide who you want to remove the menu items for. For all WordPress user Roles? Or just for your ‘Editor’ client? Or remove some menu items from the ‘Editor’ dashboard, and remove a different menu item from the ‘Author’ dashboard? After you decide what you want to remove from whom, then get the removal code for each menu item in Step 2.

Step 1 – Remove For Who?

To remove menu items for everyone, whether Administrator, Editor, Author or Contributor, simply use:
1
2
3
4
5
6
add_action( 'admin_menu', 'isa_remove_menus', 999 );
function isa_remove_menus() {
 
    // INSERT MENU ITEMS TO REMOVE HERE
 
}
To remove menu items for everyone except the ‘Administrator’ role, use:
1
2
3
4
5
6
7
8
9
10
11
12
/* Remove for all but administrator */
  
if ( ! current_user_can('manage_options') ) {
  
    add_action( 'admin_menu', 'notadmin_remove_menus', 999 );
  
}
function notadmin_remove_menus() {
  
    // INSERT MENU ITEMS TO REMOVE HERE
  
}
To remove menu items only for the ‘Author‘ role and below, but not the ‘Editor’, replace line 3 in the code above with this:
if ( ! current_user_can('delete_others_posts') ) {
Sometimes you may want to remove some menu items for the ‘Editor’ and different menu items for the ‘Author’ role. For example, you may have a custom post type that you want only the ‘Editor’ to use, so you need to remove it only from the ‘Author’ dashboard. Use:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* First remove for Editor, Author, and Contributor, then remove for Author. */
 
if ( ! current_user_can('manage_options') ) {
    add_action( 'admin_menu', 'diff_remove_menus', 999 );
}
function diff_remove_menus() {
              
    // INSERT MENU ITEMS TO REMOVE FOR EDITOR, AUTHOR, AND CONTRIBUTOR HERE
  
 
    // Now remove only for author and below, but not for Editor
    if ( ! current_user_can('delete_others_posts') ) {
 
        // INSERT MENU ITEMS TO REMOVE FOR AUTHOR HERE
 
    }
 
}
And finally, if you’re as picky as I am, you want to remove different menu items for everyone, including your own ‘Administrator’ dashboard. You want to remove some menu items for everyone, some other menu items for ‘Editor’ and below, and some other menu items for ‘Author’ and below. Use this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
add_action( 'admin_menu', 'isa_remove_menus', 999 );
function isa_remove_menus() {
  
    // INSERT MENU ITEMS TO REMOVE FOR EVERYONE
  
     
    /* remove for editor and below, but not administrator */
    if ( ! current_user_can('manage_options') ) {
 
        // INSERT MENU ITEMS TO REMOVE FOR EDITOR AND BELOW
 
    }
  
    /* remove only for author and below */
    if ( ! current_user_can('delete_others_posts') ) {
     
        // INSERT MENU ITEMS TO REMOVE FOR AUTOHR AND BELOW
 
    }
}

Step 2 – Pick Menu Items To Remove

Now choose which menu items to remove and insert these lines into the codes above. Please notice that the codes above each have a note that looks like this:
// INSERT MENU ITEMS TO REMOVE....
That’s where you’ll insert the lines from this step. Here are some menu item removal codes to choose from. These are only the ones I use most, but others exist.
To remove these top-level menu items, such as Posts, Comments, Tools, Media, Links, and Pages:
1
2
3
4
5
6
remove_menu_page( 'edit.php' );                 // Posts
remove_menu_page( 'edit-comments.php' );        // Comments
remove_menu_page('tools.php');                  // Tools
remove_menu_page('upload.php');                 // Media
remove_menu_page('link-manager.php');           // Links
remove_menu_page('edit.php?post_type=page');    // Pages
Don’t remove the Posts menu item, but remove the Categories sub-menu from under Posts:
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );
Don’t remove Posts, but remove the Tags sub-menu under Posts:
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' );
To remove a menu item for a custom post type, replace custom-post-type-name with the name of the custom post type to remove:
remove_menu_page('edit.php?post_type=custom-post-type-name');
To remove custom admin pages, such as a page with a URL path like:
'wp-admin/admin.php?page=your_page_slug'
…replace your_page_slug with the slug of your custom admin page:
remove_menu_page( 'your_page_slug' );

Remove WooCommerce Admin Sub-Menu Items

Remove the Product “Tags” menu item from under Products:
remove_submenu_page('edit.php?post_type=product', 'edit-tags.php?taxonomy=product_tag&post_type=product' );
Remove the Product “Categories” menu item from under Products:
     
remove_submenu_page('edit.php?post_type=product', 'edit-tags.php?taxonomy=product_cat&post_type=product' );
Remove the Product “Attributes” menu item from under Products:
remove_submenu_page( 'edit.php?post_type=product', 'product_attributes');

No comments: