Code #12: Remove Dashboard Menus
Hello guys, and welcome to the twelfth day of “31 Days of Coding”. Today we’re going to show you how to remove dashboard menus. Why would someone remove dashboard menus? Well, if you don’t like to have some on your sidebar, and think they are useless, they’re just taking up space, so why not delete them. This code is going to be placed on functions.php of your theme. So here’s the code:
function remove_menus () {
global $menu;
$restricted = array(__(‘Dashboard’), __(‘Posts’), __(‘Media’), __(‘Links’), __(‘Pages’), __(‘Appearance’), __(‘Tools’), __(‘Users’), __(‘Settings’), __(‘Comments’), __(‘Plugins’));
end ($menu);
while (prev($menu)){
$value = explode(‘ ‘,$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:”” , $restricted)){unset($menu[key($menu)]);}
}
}
add_action(‘admin_menu’, ‘remove_menus’);
So if you just copy the above code, and paste it on functions.php, then it will hide all the default menus. The ones in red are the ones that are going to be deleted. So just don’t include them, if you don’t want them to be hidden. So for example, if you do want the “Dashboard” menu to be displayed, then just delete that array from the code.

