Forums

wp_logout_url not redirecting (6 posts)

  1. rsnider19
    Member
    Posted 1 year ago #

    I have the following code:
    " title="Logout">Logout

    When I hover over the link, it points to this url:
    http://www.*****.com/wp-login.php?action=logout&redirect_to=http%3A%2F%2Fwww.*****.com&_wpnonce=a125e08b56

    When I click it, it sends me here:
    http://www.*****.com/wp-login.php?loggedout=true

    How can I have a logout redirect to the homepage since the proposed way of doing it doesn't work.

  2. rsnider19
    Member
    Posted 1 year ago #

    Sorry, the code is as follows

    <a href="<?php echo wp_logout_url( get_bloginfo('url') ); ?>" title="Logout">Logout</a>

  3. Michael Dance
    Member
    Posted 1 year ago #

    I'm having the same issue -- the redirect_to value appears correctly in the logout link, but it goes to the default logout page every time. Is this just broken?

  4. cleverweb
    Member
    Posted 1 year ago #

    Seem to be an issue with wp_safe_redirect() which is used by the logout process. Given redirect location cannot be verified.

  5. keesiemeijer
    moderator
    Posted 1 year ago #

    to current page:

    <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>

    to home page:

    <a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Logout</a>
  6. mrlarner
    Member
    Posted 11 months ago #

    I was having this same issue.

    wp_redirect( wp_logout_url( $foo ) ); would redirect me to /wp-login.php?action=logout& amp;redirect_to=%2Fabout%2F.

    The & was being escaped in wp_logout_url causing the logout action to send me along to /wp-login.php?loggedout=true. $_REQUEST['redirect_to'] was actually $_REQUEST['& amp;redirect_to'] causing it to default to the login page. Anyway, blah blah blah, read through the source code and fixed it with a filter inside my plugin:

    add_filter('logout_url', 'fix_logout_url');
    function fix_logout_url( $url )
    {
      $url = str_replace( '& amp;', '&', $url );
      return $url;
    }

    Basically wp_logout_url called wp_nonce_url which converts $amp; to & and then tops it off with an esc_html() converting & back to & amp;. Luckily there's a nice filter to sneak in and correct it.

    Whew! Late night goose chase complete.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.