W3docs

WordPress - Check if user is logged in

In WordPress, you can use the function is_user_logged_in() to check if a user is currently logged in.

In WordPress, you can use the function is_user_logged_in() to check if a user is currently logged in. This function returns a boolean value of true if a user is logged in, and false if they are not.

Example:

Example of checking in WordPress if a user is logged in

<?php

if (is_user_logged_in()) {
  // User is logged in
} else {
  // User is not logged in
}
Info

Watch a video course: Learn object oriented PHP

Note: You need to include wp-includes/pluggable.php file if you are using this function outside of WordPress files.