Skip links
Published on: Wordpress

How to hide admin user from another users in wordpress

Rate this post

To hide Admin user from another users just copy below code and paste in your active theme functions.php file.

Replace the <USERNAME OF ADMIN> text with the actual usernames of the users involved. You can also modify this to hide one admin from all other users (except him/herself), or based on user IDs or roles. For WordPress 3.1+.

function sangvish_pre_user_query($user_search) {
  global $current_user;
  $username = $current_user->user_login;

  if ($username == '<USERNAME OF ADMIN>') { 
    global $wpdb;
    $user_search->query_where = str_replace('WHERE 1=1',
      "WHERE 1=1 AND {$wpdb->users}.user_login != '<YOUR USERNAME>'",$user_search->query_where);