Support » Fixing WordPress » wp_logout_url not redirecting

Viewing 5 replies - 1 through 5 (of 5 total)
  • Sorry, the code is as follows

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

    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?

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

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    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>

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp_logout_url not redirecting’ is closed to new replies.