How to Hide Menu and Sub-menu items from the Admin Dashboard in WordPress ?
Hiding admin menu items can help:
Prevent accidental changes by non-admin users.
Simplify the interface for clients or contributors.
Improve security by limiting access to sensitive settings or plugin options.
You can add custom code to your theme’s functions.php
file to hide menu and submenu items.
Example: Hide Menus for Non-Administrators
add_action('admin_menu', 'custom_hide_admin_menus', 999);
function custom_hide_admin_menus() {
if(!current_user_can('manage_options')) {
//Top level menus
remove_menu_pages('tools.php'); // Tools
remove_menu_pages('edit-comments.php'); //Comments
//Submenus
remove_submenu_page('options-general.php', 'options-writing.php'); //Writing Settings
remove_submenu_page('themes.php', 'theme-editor.php'); //Theme Editor
}
}
Customizing the WordPress admin dashboard by hiding menu and submenu items helps create a cleaner, more secure experience for users.