WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/is user logged in

Contents

Description

This Conditional Tag checks if the current visitor is logged in. This is a boolean function, meaning it returns either TRUE or FALSE.

Usage

 <?php if ( is_user_logged_in() ) { ... } ?> 

Parameters

This function does not accept any parameters.

Return Values

(boolean) 
True if user is logged in, false if not logged in.

Examples

Display different output depending on whether the user is logged in or not.

<?php
if ( is_user_logged_in() ) {
	echo 'Welcome, registered user!';
} else {
	echo 'Welcome, visitor!';
}
?>

From your functions file, this code displays a personal message for logged in users.

add_action( 'loop_start', 'personal_message_when_logged_in' );

function personal_message_when_logged_in() {

if ( is_user_logged_in() ) :
 
    $current_user = wp_get_current_user();

    echo 'Personal Message For ' . $current_user->user_firstname . '!';

else :
        echo 'Non Personalized Message!';

    endif;
}

Change Log

Since: 2.0.0

Source File

is_user_logged_in() is located in wp-includes/pluggable.php.

Related

Login Tags: is_user_logged_in(), wp_login_form(), wp_loginout(), wp_logout(), wp_register()
Login URLs: wp_login_url(), wp_logout_url(), wp_lostpassword_url(), wp_registration_url()

See also index of Function Reference and index of Template Tags.