I'm trying to build a simple link to include in an email that would take the user to the WP login form, and from there to the destination post.

This should be as simple as making the link href be mydomain.com/wp-login.php?redirect_to=my-post, right? I already have a filter function hooked to login_redirect that will redirect admin users to the Dashboard and non-admin users to the members home page. I should be able to test the value of second parameter passed to my function (the requested redirect destination) and redirect based on that. The problem is, the value is empty!

I used browser dev tools to inspect the login form. It shows that the value of the hidden "redirect_to" field is set to the site index, not the value of the GET parameter. I'm thoroughly confused. How can I prevent the value from the GET parameter from being discarded?

  • Interesting. I wonder if this is a bug in WordPress core. Will do some testing and confirm.
    – Caleb
    Jul 13, 2023 at 22:21
  • Strangely, if I hook into 'login_footer' and output the $_REQUEST array, 'redirect_to' shows up with the correct value. So it looks like the code in wp-login.php should be populating the variable correctly. I just don't see how it goes from the passed value to the home URL.
    – eljefejb
    Jul 13, 2023 at 23:40

1 Answer 1


If your server or WordPress install has page caching, confirm if the login page is being cached. This would explain why the hidden field is not updating with the query parameter.

Reviewing wp-login.php, looks like if the user does not have the read capability, that they'll be redirected to the home URL. Double-check that the user has the read capability.

Additionally, if the protocol of the URL passed in redirect_to query parameter does not match the protocol of the site's URL, the user will be redirected to the admin, because wp_safe_redirect() checks that the redirect is to a URL on the same WordPress install.

Your Answer

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

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