Logout link to resend to the same page viewing earlier, Please Help !!

Discussion in 'WordPress' started by Rajnish357, Jan 3, 2012.

  1. #1
    I have wordpress blog and I'm currently using this code to provide Logout link:-
    <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>
    PHP:
    And it is working almost correct but, when I am click the Logout this on Homepage it takes me to another page and when I am on Category page it takes me to Last Updated post of the Category, same with the tags and other Archives

    And I am not using any caching plugin also.

    Please Help me to out of this problem, I will wait for your reply.
     
    Rajnish357, Jan 3, 2012 IP
  2. BRWebConsultingLtd

    BRWebConsultingLtd Member

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    28
    #2
    Try this:

    <a href="<?php echo get_settings('siteurl') . '/wp-login.php?action=logout&redirect_to=' . $_SERVER['REQUEST_URI']; ?>" title="<?php _e('Log out'); ?>"><?php _e('Log out'); ?></a>
     
    BRWebConsultingLtd, Jan 4, 2012 IP
  3. Robinsh123

    Robinsh123 Member

    Messages:
    259
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #3
    That didn't worked it is redirecting to login page
     
    Robinsh123, Jan 5, 2012 IP
  4. BRWebConsultingLtd

    BRWebConsultingLtd Member

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    28
    #4
    Oh, Okay! I see the issue!

    Here, try this for the homepage fix.

    <?php if( is_home() ) { ?>            
    <a href="<?php echo wp_logout_url( home_url() ); ?>" title="<?php _e('Log out'); ?>"><?php _e('Log out'); ?></a>
    <?php } else { ?>
    <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="<?php _e('Log out'); ?>"><?php _e('Log out'); ?></a>
    <?php } ?>
    
    PHP:
     
    BRWebConsultingLtd, Jan 5, 2012 IP