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



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



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 !