How to check user logged in or not in wordpress?

Hello Everyone!
I am come back with a new information.
If you are planning to set a different-2 custom message for registered and guest user then use my code given below :


 <?php
if ( is_user_logged_in() )
 {
//go here when user is logged in
//message for registered user
    echo 'Welcome, registered user!';
} 
else 
{
//Go here when user not logged in
//message for guest user   
  echo 'Welcome, visitor!';
}
?> 

Copy and paste my code anywhere in our wordpress theme files where you want to set this condition.
Enjoy Code!

Leave a Reply

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