Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
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 '13 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(); } ?> –  Calvin Digital Mar 19 '13 at 9:54
    
Edit your question to include the code. Code formatting in the comments is very minimal. –  s_ha_dum Mar 19 '13 at 13:36
add comment

1 Answer

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') ) .
     ">Logout</a>';
share|improve this answer
add comment

Your Answer

 
discard

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.