admin管理员组

文章数量:1134599

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:

/?logout=0b2adca060&redirect_to=/
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/
Share Improve this question asked Apr 6, 2021 at 15:59 MMKMMK 5384 silver badges11 bronze badges 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 Commented Apr 6, 2021 at 22:22
Add a comment  | 

1 Answer 1

Reset to default 1

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();
}

本文标签: wplogouturl redirect not working