How to check if user is logged-in or not in WordPress


In WordPress, we can use the is_user_logged_in() function to identify whether a current user is logged in or not. is_user_logged_in() function return true if user is logged in, false if not logged in.

<?php                                
	$logged_in = is_user_logged_in();
                    
    if ($logged_in) {
                        
        echo "User is logged in."; 
                          
    } else {
                        
        echo "User isn't logged in.";
		
    }                    
?>

Output:

If a user is logged in WordPress, it will print:

User is logged in.

Otherwise, it will print:

User isn't logged in.

References

  1. How to get author details in WordPress
  2. is_user_logged_in()- WordPress
  3. wp_get_current_user()- WordPress

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.