Hide particular admin user from userlist in WordPress dashboard

You can easily hide any particular admin user from the user list in your WordPress dashboard by this small code snippet.  Just follow these simple steps.

  • In the following code snippet replace hidden_user with your admin username you want to hide.
  • Paste the final code in your theme’s functions.php file and save it.

 

add_action('pre_user_query','hide_admin_user');
function hide_admin_user($user_search) 
{  
    global $current_user;  
    $username = $current_user->user_login;  
    if ($username != 'hidden_user') 
        {     
            global $wpdb;    
            $user_search->query_where = str_replace('WHERE 1=1', "WHERE 1=1 AND {$wpdb->users}.user_login != 'hidden_user'",$user_search->query_where);  
        }
}

Leave a Reply

Your email address will not be published. Required fields are marked *