WordPress.org

Support

Support » How-To and Troubleshooting » Show link when user is logged in

Show link when user is logged in

  • I just need 1 link to appear when users have logged in. Is there ANY way that I can accomplish this in WordPress?

    Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator Samuel Wood (Otto)

    @otto42

    WordPress.org Tech Dude

    Use code like this in your theme:

    if ( $user_ID ) {
    // user is logged in
    }
    else {
    // user is not logged in
    }

    Thanks! How exactly to do I implement that in my code? Where do I put the actual link itself?

    Seriously. Can I get a little help here? I’m dying over here!

    Wow. I guess this is why people bad mouth open source applications.

    I’m switching to Expression Engine. At least I know I’ll get consistent support there.

    no the reason people bad mouth open source applications is that they are ungrateful and demanding of peoples generousity and spare time.

    slapping some code like this

    if ( $user_ID ) {
    // user is logged in
    }
    else {
    // user is not logged in
    }

    into a post doesn’t tell anything on how to use it, keep in mind wp end users are for the most part non-programmers

    to assume everyone knows what that code is and how to use it is nothing short of an insult

    Equally, if you are going to get your hands dirty with code, and particularly code provided solely through the goodwill of others, you should enter into the spirit of open source and be prepared to learn something yourself. WordPress is designed with novice users in mind, but if you want to mess with the code itself, a small understanding of php – which is not a complicated language – would probably help.

    Providing code for free, on your own time, is certainly not an insult, particularly when the recipient is ungrateful and unwilling to spend their own time working a little of it out for themselves.

    For the record, this is the full code you need:


    //if user is logged in
    <?php if ( $user_ID ) { ?>
    [insert the link you want here]

    // otherwise do nothing
    <?php } else { } ?>

    A little politeness and humility will get you a long way.

    what with show the user nick? how will it be in code? because i think use User-nick than the link

    “A little politeness and humility will get you a long way”

    that and at least trying to read some of the documentation 😉

    jeez, some people want the world on a silver plate for free…

    Wow. Some people are amazing. For anyone else who’s looking to do this, here is an example. I put this in the sidebar in reference to the “my fav” wordpress plugin at http://www.kriesi.at/

    <?php if ( $user_ID ) { ?>
    <!-- enter info that logged in users will see -->
    <!-- in this case im running a bit of php to a plugin -->
    
    <?php mfp_display(); ?>
    
    <?php } else {   ?>
    <!-- here is a paragraph that is shown to anyone not logged in -->
    
    <p>By <a href="<?php bloginfo('url'); ?>/wp-register.php">registering</a>, you can save your favorite posts for future reference.</p>
    
    <?php } ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Show link when user is logged in’ is closed to new replies.