WordPress.org

Ready to get started?Download WordPress

Forums

Show link when user is logged in (11 posts)

  1. openlycreative
    Member
    Posted 6 years ago #

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

    Thanks!

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Use code like this in your theme:

    if ( $user_ID ) {
    // user is logged in
    }
    else {
    // user is not logged in
    }
  3. openlycreative
    Member
    Posted 6 years ago #

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

  4. openlycreative
    Member
    Posted 6 years ago #

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

  5. openlycreative
    Member
    Posted 6 years ago #

    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.

  6. shimmyshack
    Member
    Posted 6 years ago #

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

  7. gspark
    Member
    Posted 6 years ago #

    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

  8. stml
    Member
    Posted 6 years ago #

    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.

  9. truls1502
    Member
    Posted 6 years ago #

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

  10. thesmu
    Member
    Posted 6 years ago #

    "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...

  11. Chad_Coleman
    Member
    Posted 5 years ago #

    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 } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic