Sometimes we need to check a if user is logged in on the website or not. As in a case we want to show a message to the current user or we want to show some specific content to a logged in user. In some other case we want to show few messages to the visitors only. So in these type of situations in wordpress, we can use a default function that is :

is_user_logged_in()

Above mentioned function is a default wordpress function which returns a boolean value that is TRUE or FALSE. This function does not require any parameter. It simply return TRUE if a user is logged in and vice versa.

How to use :

Just simply use this function in any of your wordpress file. Generally we use this in any of the theme file like below :

<?php
if ( is_user_logged_in() ) {

	echo 'User is logged in'; //here we can show message for logged in user

} else {

	echo 'User is not logged in'; //message for not logged in user

}
?>

We can put our desired code snippet in place of messages as per our requirement. It is just simple and easy to use function. Happy coding 🙂