WordPress.org

Ready to get started?Download WordPress

Forums

Conditional login/logout link (6 posts)

  1. SupaDawg
    Member
    Posted 4 years ago #

    This seems like something that should be relatively simple, but I can't sort it out. Is this possibly a result of the placement of the echo tags?

    I'm attempting to simply get wordpress to give a login link if the user is logged out and vice versa... I have:

    <?php
    					if ( is_user_logged_in() ) {
    					    echo '<a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout" class="hunderline">Logout</a>';
    					} else {
    					    echo '<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login" class="hunderline">Login</a>';
    					};
    					?>
  2. SupaDawg
    Member
    Posted 4 years ago #

    I came across the loginout function and I think this will do the trick fine. Is it possible to style the output using css?

  3. Earthman Web & Media
    Member
    Posted 3 years ago #

    Your php syntax is wrong in several places, there were extra <?php tags and extra semicolon at the end.

    <?php
    					if ( is_user_logged_in() ) {
    					    echo '<a href="'.wp_logout_url( get_permalink() ).'" title="Logout" class="hunderline">Logout</a>';
    					} else {
    					    echo '<a href="'.wp_login_url( get_permalink() ).'" title="Login" class="hunderline">Login</a>';
    					}
    					?>
  4. Earthman Web & Media
    Member
    Posted 3 years ago #

    Did that resolve your problem? Please reply.

  5. simoncmason
    Member
    Posted 3 years ago #

    Don't know if it worked for SupaDawg but I just tried it and it worked perfectly!

    Thanks

  6. Luke Rumley
    Member
    Posted 3 years ago #

    <?php wp_loginout(); ?> will do the trick as well. http://codex.wordpress.org/Function_Reference/wp_loginout

Topic Closed

This topic has been closed to new replies.

About this Topic