So, you created a website for your customer and are afraid that he/she will be wondering around Plugins and Customizer messing something up? And now you need to know how to remove WordPress admin menu items for specific user roles? Good, because you’re in the right place.
In this post I’m going to show you two methods how to remove WordPress Admin Menu items. If you’re ready, then dive in. Before you dive in the code below, I would suggest you to take a look at the video here below. Otherwise, it may be a bit confusing what to use and how to use.
Video: How to Remove WordPress Admin Menu Items for Specific User Roles and Specific Users?
Method 1: Use Admin Menu Editor Plugin
Admin Menu Editor is a good and simple to use plugin which lets you manually edit the Dashboard menu. With the couple of clicks you can reorder the menus, show/hide specific items, change permissions etc. You can download it here.
If you need to remove admin menu item you would need to purchase a Pro version, though. Therefore, I’m going to show you how to to that by yourself with the help of couple of code snippets.
Method 2: Remove WordPress Admin Menu Items Programmatically
First, you need to decide whether you’re going to add the code snippet inside your child theme’s functions.php file or use plugin called Code Snippet for it.
I would suggest the Code Snippets option because you will not lose your modifiations in case you change theme, need to deactivate something etc.
One more thing, though – these snippets here below will just hide those menu items, they will not revoke access to the direct links. If you want to revoke the access then you would nee yo seek for another method.
How to Remove WordPress First Level Admin Menu Items?
Paste this part inside you Code Snipepts plugin. Pay attention to the comments inside the code because this will tell you which part of the code removes what. So, if you want to remove Posts menu, then just uncomment it and leave this part.
remove_menu_page( 'edit.php' ); //Posts
Now, this function here below will show you how to remove first level admin menu items (Comments, Plugins, Tools etc. Be reminded that if you hide first level menu then all the submenus will be automatically hidden. Also, this snippet will remove your Update submenu which is located under Dashboard menu
function hide_menu() {
/* DASHBOARD */
// remove_menu_page( 'index.php' ); // Dashboard + submenus
// remove_menu_page( 'about.php' ); // WordPress menu
remove_submenu_page( 'index.php', 'update-core.php'); // Update
/* REMOVE DEFAULT MENUS */
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'plugins.php' ); //Plugins
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'users.php' ); //Users
// remove_menu_page( 'edit.php' ); //Posts
// remove_menu_page( 'upload.php' ); //Media
// remove_menu_page( 'edit.php?post_type=page' ); // Pages
// remove_menu_page( 'themes.php' ); // Appearance
// remove_menu_page( 'options-general.php' ); //Settings
}
add_action('admin_head', 'hide_menu');
If you have any 3rd party plugin related menus you need to remove then just add a new line, grab a last part of the menu URL and replace it inside the code. For Example: if I want to remove Elementor then the full URL is https://yoursite.com/wp-admin/admin.php?page=elementor
Grab the last part “elementor” and add it to the code like this:
remove_menu_page( 'elementor' );
How to Remove WordPress Admin Menu submenu Items?
This time we’re going to use remove_submenu_page with two part in it. See this code here below.
remove_submenu_page( 'options-general.php', 'options-writing.php');
This code will remove Writing subenu (option-writing.php) which is located under Settings menu (options-general). So, if you want to remove submenu then you would need to change both parts inside the code. I know, it may be confusing but let me explain in the next chapter.
How to remove 3rd party plugin related menus or submenus?
I have a plugin called Fluent Forms installed and I want to remove submenu Global Settings. Now I will take a look at the Fulent forms first level menu item URL which is https://yousite.com/wp-admin/admin.php?page=fluent_forms (see the bold part? Write it down.)
Next I’ll grab a Global Settings submenu URL which is https://yoursite.com/wp-admin/admin.php?page=fluent_forms_settings (see the bold part? Write it down.)
Well, now you have both parts you would need to use in this code in order to remove Global Settings submenu:
remove_submenu_page( 'fluent_forms', 'fluent_forms_settings');
How to remove WordPress Setting page menus and submenus?
Now, to make your life a bit easier here is a snippet which will give a good starting point. This will remove Setting page submenus. If you want to remove entire Settings menu (with submenus) then add this line to your sinppet.
remove_menu_page( 'options-general.php' ); //Settings
One again comment out or remove these lines you don’t want to remove and uncomment the ones you need to remove.
function hide_submenu() {
/* REMOVE SETTINGS PAGE SUBMENUS */
// remove_submenu_page( 'options-general.php', 'options-permalink.php'); // Permalinks
remove_submenu_page( 'options-general.php', 'options-writing.php'); // Writing
remove_submenu_page( 'options-general.php', 'options-reading.php'); // Reading
remove_submenu_page( 'options-general.php', 'options-discussion.php'); // Discussion
remove_submenu_page( 'options-general.php', 'options-media.php'); // Media
// remove_submenu_page( 'options-general.php', 'options-general.php'); // General
remove_submenu_page( 'options-general.php', 'options-privacy.php'); // Privacy
}
add_action('admin_head', 'hide_submenu');
How to Remove Wooocommerce Marketing Menu?
Maybe you have a small shop, and you have no need for Woocommerce Makrketing menu, and therefore you need to remove it. Well, you can use this piece of code here below.
// This code will remove Woocommerce marketing menu (Analytics, MArketing etc).
add_filter( 'woocommerce_admin_features', function( $features ) {
return array_values(
array_filter( $features, function($feature) {
return $feature !== 'marketing';
} )
);
} );
How to Remove WordPress Customizer Admin Menu Item?
Probably it is not a wise idea to remove Appearance menu because you would also hide Widgets and Menus submenu items. Therefore, consider it carefully. Otherwise, if you want to remove submenus from Appearance add these lines inside one of the snippets you used above.
// remove_submenu_page( 'themes.php', 'widgets.php' ); // hide Widgets
// remove_submenu_page( 'themes.php', 'nav-menus.php' ); // hide Menus
remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
remove_submenu_page('themes.php', 'theme-editor.php'); // hide Theme editor
There is one more issue though – Customizer which need a bit different code snippet. But – I’ve got you covered. Just add this part inside your snippet.
$customizer_url = add_query_arg( 'return', urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 'customize.php' );
remove_submenu_page( 'themes.php', $customizer_url );
How to Remove WordPress Admin Menu Items for Specific User Roles?
Here’s the scenario for you.
- You created a site for your customer
- He/she needs access to the site
- Customer need administrator rights but you don want him/her to access all the menus
So, what to do? Well, let’s create a new user role which has all admin rights but the role is called Site Admin.
How to Clone a WordPress Administrator user role?
It is easy. Just go to the Code Snippets and paste this code here below.
add_action('init', 'cloneRole');
function cloneRole() {
$adm = get_role('administrator');
$adm_cap= array_keys( $adm->capabilities ); //get administator capabilities
add_role('site_admin', 'Site admin'); //create new role
$new_role = get_role('site_admin');
foreach ( $adm_cap as $cap ) {
$new_role->add_cap( $cap ); //clone administrator capabilities to new role
}
}
Press on “Save and activate” button and the role is cloned. Now you can delete this snippet.
How to Remove WordPress Admin Menu Items for Specific User Roles?
It is rather easy. Take a look at the role slug in the snippet we used to clone a role. There is a user role called Site admin and the slug is site_admin. Write it down because you’re gonna need it now.
Now, if you want to remove WordPress admin menu items for specific user role (Site Admin, for example) then you would need to modify your snippet a bit. Something like this:
function hide_siteadmin() {
// Use this for specific user role. Change site_admin part accordingly
if (current_user_can('site_admin')) {
/* DASHBOARD */
remove_submenu_page( 'index.php', 'update-core.php'); // Update
}
}
add_action('admin_head', 'hide_siteadmin');
As you see, we removed Update submenu for Site admin user role.
How to Remove WordPress Admin Menu Items for Specific Users?
Once again, this is fairly easy. This time you would need to modify your snippet to look like this one here below.
function hide_demouser() {
// Change username "demouser"
$user = wp_get_current_user();
if($user && isset($user->user_login) && 'demouser' == $user->user_login) {
/* DASHBOARD */
remove_submenu_page( 'index.php', 'update-core.php'); // Update
}
}
add_action('admin_head', 'hide_demouser');
Let put everything together
If everything I described here is a bit confusing then just grab this code here below and remove the lines you don’t need. It contains everything I showed you above and remove menu items for Site Admin user role. Inside the code there is a commented out part for Demouser.
As a bonus I included some examples for the well-known plugin menus you may want to remove.
function hide_menu() {
// Use this for specific user role. Change site_admin part accordingly
if (current_user_can('site_admin')) {
// Uncomment the part below if you need it to specific user. Change username "demouser"
/* $user = wp_get_current_user();
if($user && isset($user->user_login) && 'customer' == $user->user_login) { */
/* DASHBOARD */
// remove_menu_page( 'index.php' ); // Dashboard + submenus
// remove_menu_page( 'about.php' ); // WordPress menu
remove_submenu_page( 'index.php', 'update-core.php'); // Update
/* WP DEFAULT MENUS */
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'plugins.php' ); //Plugins
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'users.php' ); //Users
// remove_menu_page( 'edit.php' ); //Posts
// remove_menu_page( 'upload.php' ); //Media
// remove_menu_page( 'edit.php?post_type=page' ); //Pages
// remove_menu_page( 'themes.php' ); //Appearance
// remove_menu_page( 'options-general.php' ); //Settings
/* SETTINGS PAGE SUBMENUS */
//remove_submenu_page( 'options-general.php', 'options-permalink.php'); // Permalinks
remove_submenu_page( 'options-general.php', 'options-writing.php'); // Writing
remove_submenu_page( 'options-general.php', 'options-reading.php'); // Reading
remove_submenu_page( 'options-general.php', 'options-discussion.php'); // Discussion
remove_submenu_page( 'options-general.php', 'options-media.php'); // Media
//remove_submenu_page( 'options-general.php', 'options-general.php'); // General
remove_submenu_page( 'options-general.php', 'options-privacy.php'); // Privacy
/* APPEARANCE SUBMENUS */
// remove_submenu_page( 'themes.php', 'widgets.php' ); // hide Widgets
// remove_submenu_page( 'themes.php', 'nav-menus.php' ); // hide Menus
remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
remove_submenu_page('themes.php', 'theme-editor.php'); // hide Theme editor
/* HIDE CUSTOMIZER MENU */
$customizer_url = add_query_arg( 'return', urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 'customize.php' );
remove_submenu_page( 'themes.php', $customizer_url );
/* Plugin related submenus under Settings page */
remove_submenu_page( 'options-general.php', 'webpc_admin_page' ); // WebP converter
remove_submenu_page( 'options-general.php', 'kadence_blocks' ); // Kadence Blocks
/* 3rd party plugin menus */
// remove_menu_page( 'snippets' ); // Code snippets
// remove_menu_page( 'elementor' ); // Elementor
// remove_menu_page( 'rank-math' ); // Rank Math
// remove_menu_page( 'Wordfence' ); // Wordfence
// remove_menu_page( 'WPML' ); // WPML
// remove_menu_page( 'fluent_forms' ); // Fluent Forms
// remove_menu_page( 'ct-dashboard' ); // Blocksy
}
}
add_action('admin_head', 'hide_menu');
How to Remove WordPress Admin Bar Items?
One more thing. Although you removed menu items from the WordPress Admin there is a small problem. That is: customizer menu item is still visible on front-end admin bar. So, if you want to remove Worpress admin bar items then this snippet will remove some of them for Site Admin user role.
// Remove frontend admin bar items
function remove_admin_bar_items($wp_admin_bar) {
if (current_user_can('site_admin')) {
// Plugin related admin-bar items
$wp_admin_bar->remove_node('blocksy_preview_hooks');
// WordPress Core Items
$wp_admin_bar->remove_node('updates');
$wp_admin_bar->remove_node('comments');
// $wp_admin_bar->remove_node('new-content');
$wp_admin_bar->remove_node('wp-logo');
//$wp_admin_bar->remove_node('site-name');
//$wp_admin_bar->remove_node('my-account');
//$wp_admin_bar->remove_node('search');
$wp_admin_bar->remove_node('customize');
}
}
add_action('admin_bar_menu', 'remove_admin_bar_items', 999);