I link to WP's login page passing: redirect_to=play

...ttp://www.my.com/wp-login.php/?redirect_to=play">Click here...

I use the value (in this case: play) as a flag, not an actual redirect url, because I intercept the redirect request using:

function my_login_redirect($redirect_to, $requested_redirect_to, $user)
add_filter('login_redirect', 'my_login_redirect', 10, 3);

Expected result: $requested_redirect_to would contain the value: play. However, wp login does not relay the original redirect_to value, in fact no mater what I do, the 2 params $requested_redirect_to and $redirect_to are always empty; only $user contains data.

How do I pass my original redirect_to value all the way through the login process and into the filter: login_redirect?

  • i tried your code and i see play in $redirect_to. it can be other plugins that change this value with filter. try to change the priority to -10 e.g.
    – mmm
    Jan 22, 2018 at 22:18
  • mmm, thank you for looking at this. I lowered the priority. Same result. To be clear: array(1) { ["redirect_to"]=> string(4) "play" } does appear on the login page. However, login form submission does not relay the value back to the WP filter: login_redirect; login_redirect does fire, but the parameters are now empty.
    – MLH
    Jan 22, 2018 at 22:58
  • Are the parameters sent at all (check your browser's dev tools)? Does var_dump($_REQUEST) contain them?
    – janh
    Jan 23, 2018 at 8:31
  • I found the problem : you forget to return $redirect_to in your code then the URL is lost.
    – mmm
    Jan 23, 2018 at 8:44

1 Answer 1


You can use login_redirect filter. See here http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

I think this is what you are looking for.

This will normally redirect all logins. To be able to redirect only when you want, you can use a query string parameter in the URL. Check for the parameter, if it exists redirect.

Try to add this in your template functions.php file:

add_action( 'login_form' , 'glue_login_redirect' );
function glue_login_redirect() {
    global $redirect_to;
    if (!isset($_GET['redirect_to'])) {
        $redirect_to = 'YOURURLHERE';
        $redirect_to = $_GET['redirect_to'];
  • Yes. I was using the wrong hook, login_form with a global var is the fix. Thank you Dharmishtha.
    – MLH
    Jan 23, 2018 at 21:10

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.