• Resolved senorwooly

    (@senorwooly)


    After users login at my site, I want to redirect them to the page they were previously at.

    For example, users at ‘Page A’ click on the Login link. They get taken to the WordPress login page. Then, after successfully logging in, I want them redirected back to ‘Page A’.

    I know about the redirect plugin, but that only takes you to specific, pre-determined pages.

    Can anyone help me on this?

    Thanks,
    Sr. Wooly

Viewing 4 replies - 1 through 4 (of 4 total)
  • Not ideal because it requires editting a core WP file… but since you asked… it can be done like so…

    wp-login.php

    Line 424 – 426…

    } else {
    		$redirect_to = admin_url();
    	}

    Change to…

    } else {
    		$redirect_to = $_SERVER[HTTP_REFERER];
    	}

    Not sure how reliable that is, but it does archieve the desired result…

    Thread Starter senorwooly

    (@senorwooly)

    Thanks so much. That works. Just have to make a note about the change so I can do it again after updating WP.

    Much appreciated.

    nerdspawn

    (@nerdspawn)

    Was wondering if this would be an option for my site…

    We’ve got lots of private content which users can only access after they log in. How it currently works:

    1. Members get sent a URL via email to a private document/page located on the site.
    2. They click the URL and if they’re not logged in, they get the 404 page.
    3. On the 404 page, they’re able to click through to the login page.
    4. After logging in, they get redirected to the home page.

    Is it possible to redirect to the URL they were originally trying to access before getting the 404 page (and then logging in)? Hope that makes sense… any help and/or advice is greatly appreciated. ??

    Thanks for this solution, not ideal given, as you say, the need to edit core files (ahhh!), but it works a treat!

    Likely (hopefully) this will be addressed in a future WP release.

    @nerdspawn Sounds like maybe you should add a PHP variable to your 404 template that stores the referrer, then use that variable instead of referrer.

    Hope this helps!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Any way to redirect to previous page after login’ is closed to new replies.