• I’d like to display some (non-WP) content when a user is logged in, but haven’t had much success. A quick turn around the forums revealed this topic, from which I have extracted this:

    get_currentuserinfo();
    if (isset($user_ID) && ('' != intval($user_ID))) {
    // do stuff here
    }

    I’m at work at the moment, so can’t test this, but can ayone tell me if this code snippet will do the trick, or point me in the right direction if it won’t?

Viewing 8 replies - 1 through 8 (of 8 total)
  • If that doesn’t work try:
    <?php if ( $user_ID ) : ?>
    whatever you want to display to logged in people
    <?php endif; ?>

    Thread Starter Cam

    (@cam)

    Thanks Ian… I’ll give that a bash and see what happens.

    Thread Starter Cam

    (@cam)

    Update: Nope, nothing happened. Is there anything else I can try?

    Set $user_login to global before calling get_currentuserinfo(), then use that to test on:

    <?php
    global $user_login;
    get_currentuserinfo();
    if ($user_login) :
    ?>

    ~Do your login stuff~

    <?php endif; ?>

    Thread Starter Cam

    (@cam)

    Works like a charm — many thanks Kafkaesqui!

    The example above worked well for me, but how would I go about inserting an “else” statement to handle people not logged on at all?

    To clarify my previous post, I’d like to have an option at the top of the screen that toggles between “Login” for those not yet logged in and “Logout” for those already logged in.

    Right now I’m looking at a permanent “Login” option and a conditionally appearing “Logout” option. I’d like to switch between the two, though.

    Nevermind. I figured it out.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Conditionally displaying content for logged in user’ is closed to new replies.