HOW TO: Remove Admin Menus from WordPress Dashboard


In this tutorial I will tell you what code I have used to remove admin menus from the WordPress backend of a site with multiple users having near-admin rights. There I used a theme written by me almost from scratch and of course I din’t want anyone else to mess up my work by tinkering with the settings! More than that, I din’t want to confuse them with admin menus that they have no idea about. To achieve this keep-the-dashboard-simple mission I decided to do away with the entire set of Dashboard, Links, Appearance, Tools, Settings and Plugins menus. By a set I mean the menu and its submenus as well, obviously.

Without further ado, here’s the PHP:


function remove_menus () {
global $menu;
$restricted = array(__('Dashboard'), __('Links'), __('Appearance'), __('Tools'), __('Settings'), __('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');

As you can see, I have entered the menus I want to discard under the $restricted array. I borrowed this code from the Hungred Dot Com and here’s is the link to the original article, which not only explains in detail the mechanism of action of the code but also tells you how you can gain even greater control on your admin menus to fine tune them to your requirements:

Remove WordPress Admin Menu Without Affecting WordPress Core System (Hungred Dot Com)

Remember the above code mentioned doesn’t remove actual admin pages, users can still visit the pages if they know the URL! That pretty much addresses my requirement but if you need to prevent access completely, refer to the relevant code given in the original guide I linked to.


One response to “HOW TO: Remove Admin Menus from WordPress Dashboard”

Leave a Reply

Your email address will not be published. Required fields are marked *