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.

On our website we have a "Join" button in the top right corner and a log in / log out link using <?php wp_loginout(); ?> . Instead of having the log in / log out link we would like to have it display in a button. It should ready "Login" when something like if ( is_user_logged_in() ) is false and "Log Out" when it's true.

The Code for the Join Button is:

<a href="www.google.com" class="join-button">Join</a>

so the code for the Log in / log out button should have the same .join-button class.

Style for .join-button:

.join-button {
-moz-box-shadow:inset 0px 1px 0px 0px #f5840c;
-webkit-box-shadow:inset 0px 1px 0px 0px #f5840c;
box-shadow:inset 0px 1px 0px 0px #f5840c;
background-color:#f5840c;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #f5840c;
display:inline-block;
color:#ffffff;
font-family:Arial;
font-size:14px;
font-weight:bold;
padding: 1px 4px;
text-decoration:none;
text-shadow:1px 1px 0px #f5840c;
}

Could someone please help me write the code to achieve this task?

share|improve this question

1 Answer 1

here is a very simple function that should do it:

function loginout_button_wpa89153($echo = true){
    if (is_user_logged_in()){
        $url = wp_logout_url(get_permalink());
        $anchor = "Logout";
    }else{
        $url = wp_login_url(get_permalink());
        $anchor = "Login";
    }
    $button = '<a href="'.$url.'" class="join-button">'.$anchor.'</a>';
    if ($echo)
        echo $button;
    else
        return $button;
}
share|improve this answer
    
Thanks for your work with that, however, it's not displaying anything on my end. –  Patrick Mar 3 '13 at 17:17
    
did you call it? –  Bainternet Mar 3 '13 at 18:20
    
@Patrick instead of <?php wp_loginout(); ?> replace it with <?php loginout_button_wpa89153(); ?> –  Rajeev Vyas Apr 2 at 7:33

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.