Sometimes you just want to clean up the WordPress Admin side bar. Whether you want to limit your client’s access to certain sections.
Remove a Whole Menu in WordPress
For instance Appearance, sometimes you don’t want to give them access to editing the custom theme you developed. Just paste this code into your functions file and add // before any menu you might want to keep or you can just keep the ones you want to delete/hide from the sidebar.
// Remove Admin menus
function delete_menu_items() {
remove_menu_page('index.php'); // Dashboard
remove_menu_page('edit.php'); // Posts
remove_menu_page('upload.php'); // Media
remove_menu_page('link-manager.php'); // Links
remove_menu_page('edit.php?post_type=page'); // Pages
remove_menu_page('edit-comments.php'); // Comments
remove_menu_page('themes.php'); // Appearance
remove_menu_page('plugins.php'); // Plugins
remove_menu_page('users.php'); // Users
remove_menu_page('tools.php'); // Tools
remove_menu_page('options-general.php'); // Settings
}
add_action( 'admin_init', 'delete_menu_items' );
Remove a Sub Menu from WordPress
Just need to remove a submenu, for instance if you remove the whole appearance tab then there is nowhere to click to get to the widgets section, which is probably important. Here are a few submenus you might want to remove. If you want to add others to remove, the first parameter is the main tab (hover the tab and look at the bottom of your browser to see the url path to use, i.e filename.php) Second parameter is the sub page to remove, again use the hover link trick to figure out the .php name to add.
// Remove Admin sub menus
function delete_sub_menu() {
$page = remove_submenu_page( 'index.php', 'index.php' ); //Home
remove_submenu_page( 'index.php', 'update-core.php' ); //WordPress updates
remove_submenu_page( 'themes.php', 'themes.php' ); //Themes
remove_submenu_page( 'themes.php', 'theme-editor.php' ); //Theme Editor
}
add_action( 'admin_menu', 'delete_sub_menu', 999 );