How to Hide Unnecessary Menu Items from WordPress Admin Dashboard
In this video, I will show you how you can hide unnecessary Dashboard Menu items on the WordPress website.
function remove_dashboard_menu_items() { global $menu; // Uncomment the lines below to exclude specific menu items // unset($menu[5]); // Removes "Posts" // unset($menu[10]); // Removes "Media" // unset($menu[20]); // Removes "Pages" unset($menu[25]); // Removes "Comments" unset($menu[60]); // Removes "Appearance" unset($menu[65]); // Removes "Plugins" unset($menu[70]); // Removes "Users" unset($menu[75]); // Removes "Tools" unset($menu[80]); // Removes "Settings" remove_menu_page('index.php'); // Removes the Dashboard home page } add_action('admin_menu', 'remove_dashboard_menu_items');
Use this PHP code snippet in your WordPress website using any code manager plugin like WP Code, Code Snippets, etc.
You can also paste the code directly into the function.php file of your theme.
Here, Note that this code only hides the menu, it won’t remove it completely. You can easily restore any menu just by commenting on the line.
Hide Wordpress Dashboard Items based on User Role
If you want to Hide Wordpress Dashboard Items based on User Role then you can use the below Code snippets instead.
function remove_dashboard_menu_items() { global $menu; $user = wp_get_current_user(); $user_role = $user->roles[0]; // Get the first user role assigned to the user if ($user_role == 'administrator') { // Admin can see all menu items return; } elseif ($user_role == 'editor') { // Editors can see Pages and Posts unset($menu[25]); // Removes "Comments" unset($menu[60]); // Removes "Appearance" unset($menu[65]); // Removes "Plugins" unset($menu[70]); // Removes "Users" unset($menu[75]); // Removes "Tools" unset($menu[80]); // Removes "Settings" remove_menu_page('index.php'); // Removes the Dashboard home page } else { // All other users see limited menu items unset($menu[5]); // Removes "Posts" unset($menu[10]); // Removes "Media" unset($menu[20]); // Removes "Pages" unset($menu[25]); // Removes "Comments" unset($menu[60]); // Removes "Appearance" unset($menu[65]); // Removes "Plugins" unset($menu[70]); // Removes "Users" unset($menu[75]); // Removes "Tools" unset($menu[80]); // Removes "Settings" remove_menu_page('index.php'); // Removes the Dashboard home page } } add_action('admin_menu', 'remove_dashboard_menu_items');
Hi,
What is the number for the menu item and where do I look for it:
unset($menu[?]); // Removes “Templates”
Regards
Hii Brother,
I’m also facing the same issue. Can you please help me to solve the same to hide the Elementor templates from the menu bar specifically for Authors?
unset($menu[?]); // Removes “Templates” or something.