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.

About Yasser Shaikh

Hello, I am a Web Dev, employed with Media.Net where I primarily work on ASP.NET MVC and Angular JS based developement.

Questions? Enquiries? Comments? Or even just want to say “Hi” to me, you are welcome to all of that. Just drop me a message at “mail@yassershaikh.com” and I’ll get back to you as soon as possible.

Cheers !

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>