Categories
Uncategorized

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

[sourcecode language=”php”]

<?php

if ( is_user_logged_in() ) 
{
 echo ‘Hello, user, you are logged in!’;

else
{
 echo ‘Halo !, Stranger ‘;
}

?>

[/sourcecode]

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.