How to remove menu items from the WordPress admin sidebar

 In Wordpress Admin

The following code will disable left sidebar menus on the admin area (for all the users).

add_action( ‘admin_menu’, ‘tpk_menulinks_remove’ );
function tpk_menulinks_remove() {
remove_menu_page(‘index.php’); // This is for Dashboard
remove_menu_page(‘edit.php’); // This is for Posts
remove_menu_page(‘upload.php’); // This is for Media
remove_menu_page(‘link-manager.php’); // This is for Links
remove_menu_page(‘edit.php?post_type=page’); // This is for Pages
remove_menu_page(‘edit-comments.php’); // This is for Comments
remove_menu_page(‘themes.php’); // This is for Appearance
remove_menu_page(‘plugins.php’); // This is for Plugins
remove_menu_page(‘users.php’); // This is for Users
remove_menu_page(‘tools.php’); // This is for Tools
remove_menu_page(‘options-general.php’); // This is for Settings
}

The following code will disable the menus  for one specific user.

function tpkmenuremove()
{
global $menu;
global $current_user;
get_currentuserinfo();
if($current_user->user_login == ‘username’)
{
$restricted = array(__(‘Posts’),
__(‘Media’),
__(‘Links’),
__(‘Pages’),
__(‘Comments’),
__(‘Appearance’),
__(‘Plugins’),
__(‘Users’),
__(‘Tools’),
__(‘Settings’)
);
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’, ‘tpkmenuremove’);

 

where “username” is the user that you want to restrict. You can also put “if($current_user->user_login != ‘admin’)” to apply these restrictions to all the users excluding “admin” .

Recent Posts

Leave a Comment

Start typing and press Enter to search