Hide Admin Menu Items from Specific Users in Wordpress
If you develop a site for a client add this function to your themes functions.php file and change the user ID (in the example below it's 3) to the ID of the user you want to hide certain admin menu items.
You can get the user's ID by hovering over the users name and looking for "user_id=3" in the bottom left corner of your browser or click on the user name and check the ID in the URL
In the function below I've added all the admin page names for reference but commented out // the pages I want the user to see.
function remove_menus(){
$user_ID = get_current_user_id();
if ($user_ID == '3') {
//remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'edit.php' ); //Posts
//remove_menu_page( 'upload.php' ); //Media
//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_menu', 'remove_menus' );
You can get the user's ID by hovering over the users name and looking for "user_id=3" in the bottom left corner of your browser or click on the user name and check the ID in the URL
In the function below I've added all the admin page names for reference but commented out // the pages I want the user to see.
function remove_menus(){
$user_ID = get_current_user_id();
if ($user_ID == '3') {
//remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'edit.php' ); //Posts
//remove_menu_page( 'upload.php' ); //Media
//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_menu', 'remove_menus' );
Comments
Post a Comment