WordPress – How to check if user logged in

In WordPress many a times you might need to check whether a user is logged in or not. This can be easily done, check the code below

Code


<?php

if ( is_user_logged_in() )  
{
    echo 'Hello, user, you are logged in!';
} 
else
{
    echo 'Halo !, Stranger ';
}  

?>

Explanation

The is_user_logged_in() is a built in WordPress function which return a boolean value. A value of true is returned is the user is logged in or false is returned otherwise.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>