How to check if user is logged-in or not in WordPress
In WordPress, we can use the is_user_logged_in() function to identify whether a current user is logged in or not. is_user_logged_in() function return true if user is logged in, false if not logged in.
<?php
$logged_in = is_user_logged_in();
if ($logged_in) {
echo "User is logged in.";
} else {
echo "User isn't logged in.";
}
?>Output:
If a user is logged in WordPress, it will print:
User is logged in.Otherwise, it will print:
User isn't logged in.References
- How to get author details in WordPress
- is_user_logged_in()- WordPress
- wp_get_current_user()- WordPress