Is there a conditional tag or something that I can use to display a certain text if a user is logged in, and something else if a user is logged out in my template files?
Is there a conditional tag or something that I can use to display a certain text if a user is logged in, and something else if a user is logged out in my template files?
The $user_ID global will be set for a logged on user, once get_currentuserinfo() has been called. However, this is actually always called at WP->init, so you don't have to call it yourself.
So in a theme, you can just do:
if ($user_ID) {
// logged on
} else {
// not logged on
}
There's various other globals too. $user_identity is the nickname, etc. Look in the link above for some of the various globals available to you.
For me, the $user_ID variable is empty even though I'm logged in. Any reasons why this might be occurring?
This topic has been closed to new replies.