How can you check if specific username is logged in?

  • I'd like to use specific css on the admin panel for a specific user. – Shae Nov 29 '12 at 22:31

wp_get_current_user then compare the object that's returned user_login proprety with the specific username you'd like to check against.

add_action('admin_init', 'wpse74389_check_username');
function wpse74389_check_username()
    $user = wp_get_current_user();

    if($user && isset($user->user_login) && 'username_to_check' == $user->user_login) {
        // do stuff
  • How can this be modified to check for all usernames that are not username_to_check – Travis Pflanz Nov 27 '18 at 5:19
  • @TravisPflanz if you're just looking to check for a logged in user: developer.wordpress.org/reference/functions/is_user_logged_in Otherwise just modify the function to take the username as a parameter instead of being hardcoded. – chrisguitarguy Nov 30 '18 at 20:08
  • The question is not about the current user, he means a specific user – Mr. Jo Jul 15 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.