How to Exclude Dashboard links in WordPress

How to Exclude Dashboard links in WordPress

Exclude Dashboard links in WordPressSometimes you will have clients login to their sites and you don’t want them to mess anything up. There is a way  to hide certain plugins and pages from users so they don’t even see them. Here I will demonstrate how to exclude dashboard links in WordPress.

Check What User Is Logged In

First, log into the dashboard and go to the users section. Highlight your username to see what ID it is. In my case it was ‘3’.

function my_remove_menu_pages() {
	$user_id = get_current_user_id();
if ($user_id !== 3) {//check the user id. Change to yours
    // not specific user then...

Use the WordPress function remove_menu_page() to target which pages to hide. Sometimes it take some work to hid some plug in links. Here are a few of the  common links you can easily hide for other users.

Remove The Links

remove_menu_page( 'edit.php' );                   //Posts
remove_menu_page( 'upload.php' );                 //Media
remove_menu_page( 'edit-comments.php' );          //Comments
remove_menu_page( 'themes.php' );                 //Appearance
remove_menu_page( 'users.php' );                  //Users
remove_menu_page( 'tools.php' );                  //Tools
remove_menu_page( 'options-general.php' );        //Settings
remove_menu_page( 'edit.php?post_type=acf' );
remove_menu_page( 'stop_spammers' );
remove_menu_page( 'wpseo_dashboard' );
remove_menu_page( 'theme_my_login' );
 
} else {}
};
add_action( 'admin_menu', 'my_remove_menu_pages', 999 );