I originally came here to find help on creating a string of text that would display a login link, and when the user was logged in it would should their username. Travis Pflanz had the answer for another user, which works great but I'd like to expand on it further and add a log out link after the user display name when logged in. My PHP experience is extremely low and rely on copy/pasting code. Any help would be greatly appreciated!

  • 1
    Please post what code you've tried, or what code you are starting with. At the very least post a link to the solution you mention.
    – s_ha_dum
    Mar 18, 2013 at 14:35
  • I guess that would have helped, s_ha_dum, sorry about that. Here is the current code in use----------> <?php global $current_user; get_currentuserinfo(); ?> <?php if ( is_user_logged_in() ) { echo 'Welcome: ' . $current_user->display_name . "\n"; } else { wp_loginout(); } ?> Mar 19, 2013 at 9:54
  • Edit your question to include the code. Code formatting in the comments is very minimal.
    – s_ha_dum
    Mar 19, 2013 at 13:36

1 Answer 1


The key function to use is wp_logout_url. This function returns the URL for a user to logout.

You can construct a regular anchor tag / link markup around it and style that as you see fit.

wp_logout_url takes an optional $redirect argument to send the user to after logout. Here's a sample with markup and the TLD as redirect:

echo '<a class="button" title="Log me out" href="' .
        wp_logout_url( get_bloginfo('url') ) .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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