WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to display a logout link when users are logged in and make it disappear when they are not logged in.

The code I have so far works for the login and register links due to a plugin that I have installed, so 'login' and 'register' disappear just fine, now for logout I need some assistance... Here is the code:

<ul id="login-navigation">
<?php if ( is_user_logged_in() ) {
          $user = wp_get_current_user();
          echo 'Welcome <strong>'.$user->display_name.'!</strong> ';
} else { ?>
    <a href="/wp-login.php?action=register" class="simplemodal-register" >Register</a>
<?php }
wp_loginout( get_permalink() ); ?>
share|improve this question

Try using wp_loginout(). It automatically handles those conditions.

share|improve this answer
Sorry Im somewhat of a noob. How can I implement this? – Brian Aug 3 '12 at 6:54
put the above function wherever you want the login/logout link to appear thats it. This would show a logout link when the user is logged in and viceversa. – Joshua Abenazer Aug 3 '12 at 6:57
I changed the code how you suggested, it's above. I made it so that it redirects to the current page but when I try to login from home it takes me to a post. – Brian Aug 3 '12 at 7:17
paste your updated code – Joshua Abenazer Aug 3 '12 at 7:30
Its the one in the post. That's how it looks now. See how I added <?php wp_loginout( get_permalink() ); ?> – Brian Aug 3 '12 at 8:15

Try this:

<ul id="login-navigation" >
    if (is_user_logged_in()) {
        $user = wp_get_current_user();
        echo __('Welcome') . ' <strong>' . $user->display_name . '!</strong> ';
    } else { ?>
        <a href="<?php echo site_url('wp-login.php?action=register') ?>" class="simplemodal-register" ><?php echo __('Register'); ?></a>
    <?php } ?>
    <?php wp_loginout( $_SERVER['REQUEST_URI'] ); ?>
share|improve this answer
Thank you very much! That did the job! – Brian Aug 3 '12 at 15:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.