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
}

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

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