is_user_logged_in

Home » Functions » is_user_logged_in

The is_user_logged_in() function in WordPress is a conditional tag that checks whether the current user has logged in or not. This function returns true if the user is logged in and false if the user is not logged in.

This function is commonly used in WordPress themes and plugins to display certain content or functionality only to logged-in users. For example, you might want to hide the login form for users who are already logged in, or display a personalized welcome message to logged-in users.

Here’s an example usage code:

if ( is_user_logged_in() ) {
    // Display content for logged-in users
} else {
    // Display content for non-logged-in users
}

In the above example, the code checks if the user is currently logged in using the is_user_logged_in() function. If the user is logged in, the code will display content for logged-in users, otherwise, it will show content for non-logged-in users.

Overall, the is_user_logged_in() function is an essential tool for WordPress developers to control the visibility of content and functionality on their websites based on user login status.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.