Code #12: Remove Dashboard Menus

Hello guys, and wel­come to the twelfth day of “31 Days of Cod­ing”. Today we’re going to show you how to remove dash­board menus. Why would some­one remove dash­board menus? Well, if you don’t like to have some on your side­bar, and think they are use­less, they’re just tak­ing 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:

func­tion remove_menus () {
global $menu;
$restricted = array(__(‘Dash­board’), __(‘Posts’), __(‘Media’), __(‘Links’), __(‘Pages’), __(‘Appear­ance’), __(‘Tools’), __(‘Users’), __(‘Set­tings’), __(‘Com­ments’), __(‘Plu­g­ins’));
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 hid­den. So for exam­ple, if you do want the “Dash­board” menu to be dis­played, then just delete that array from the code.

blog comments powered by Disqus