0
logout_url = wp_logout_url( $custom_login_url);
echo "<a class='handler-login-link logout' href='{$logout_url}'>".__("Logout","pixel_framework")."</a>";

I have created a custom logout link that is supposed to redirect users to a custom login page (within the same domain).

Logout is working fine, but the redirection is not working at all. After logging out redirected to the default wp-login page.

I tried to inspect HTML behind the link it is like this:

https://example.com/?logout=0b2adca060&redirect_to=https://example.com/haendler-login/
1
  • 1
    That's wrong. The logout URL should be https://example.com/wp-login.php?action=logout&_wpnonce=12345&redirect_to= etc. (and the redirect-to URL urlencoded). i.e. it should use the login page to log out. Unless you have a different logout handler, and a logout_url filter from one of your plugins? I'd guess that logout handler doesn't support the redirect.
    – Rup
    Apr 6, 2021 at 22:22

1 Answer 1

0

Use this logout link <li class="signOut"><a href="<?php echo wp_logout_url(); ?>" title="Logout">Logout</a></li>

And add below code in your functions.php file to redirect the user to the page you want:

add_action( 'wp_logout', 'auto_redirect_user_after_logout');
function auto_redirect_user_after_logout(){
  wp_redirect( 'https://example.com/haendler-login/' );
  exit();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.