简体   繁体   中英

WordPress is_user_logged_in()

I'm trying to see if the user is logged in on WordPress by using the intended function: is_user_logged_in() .

Weird is, when I log out, it still returns true. What am I doing wrong?

function test() {
    if(is_user_logged_in()) {
      ...
    }
}
add_action( 'init', 'test' );

Try your code by this way.

if ( is_user_logged_in() ) 
{
    $logged = TRUE
} 
else 
{
    echo 'false';
    $logged = FALSE
}

Then just add this condition on any content :

if($logged) 
{
    echo 'Logged in';
} 
else 
{
    echo 'not logged in'; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM