WordPress.org

Ready to get started?Download WordPress

Forums

Hide a <div> when user is logged in. (7 posts)

  1. Xitanto
    Member
    Posted 7 years ago #

    My site (MediaHug.com) has a small message bar at the top that reminds readers to register. I'd like to know how I can control it so that only guests can view the bar.

    :) Help much appreciated.

  2. moshu
    Member
    Posted 7 years ago #

    I have something like this in one of the blogs:

    <?php
    global $user_login, $user_identity;
    get_currentuserinfo();
    if ($user_login) :
    ?>
    <div class="whatever">
    <strong>Hello <?php echo $user_identity; ?>!<br />
    </div>
    <?php else : ?>
    <div class="mydiv">
    <b>Welcome! Hey, Login ... +your text </b>
    </div>
    <?php endif; ?>

  3. Xitanto
    Member
    Posted 7 years ago #

    Moshu - thanks. :P

    I've put it in to the code, and it does work well.

    <?php
    global $user_login, $user_identity;
    get_currentuserinfo();
    if ($user_login) :
    ?>
    <?php else : ?>
    <?php easy_announcement(); ?>
    <?php endif; ?>

    Any way to trim it down a bit? I don't need to find the user's login name, I just need to block them from seeing <?php easy_announcement(); ?> when they're logged in.

    In other words, is it possible to cut the code down a fraction?

  4. moshu
    Member
    Posted 7 years ago #

    The only thing you can take out (though I am not a coder!!! - you were warned:) - might be the user_identity.

  5. Xitanto
    Member
    Posted 7 years ago #

    hmm... Might wait till a coder can give me an answer on that one. :P But thanks. ^_^

  6. MS-DOS_1991
    Member
    Posted 7 years ago #

    Well you could just ... try to cut out things and see what happens :D

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

  7. delfim
    Member
    Posted 7 years ago #

    This topic is very useful when running PHP (using PHP-exec or another one) in a post, just to inform the visitors wether they are currently logged in or not, when you use the HIDETHIS plugin or a post restriction plugin.
    Example:

    <font color="red" size="1" face="arial"><phpcode>
    <?php global $user_login, $user_identity;
    get_currentuserinfo();
    if ($user_login) :
    ?>
    You are OK!
    <?php else : ?>
    You are off!
    <?php endif; ?>
    </phpcode></font>

Topic Closed

This topic has been closed to new replies.

About this Topic