Redirect to previous page upon login

Hello,

I was wondering if it was possible to have it so when somebody logins on my site it redirects them on the page they were on before upon successfully logging in.

Thanks!

  • Jude
    • DEV MAN

    Hey @nick

    Thanks for getting in touch !

    Here is some code to do this for you. Take a look

    add_action( 'wp_login',  'your_function_221' );

    function your_function_221($user_login, $user) {
    $referrer = $_SERVER['HTTP_REFERER'];
    wp_redirect( $referrer );
    exit ;
    }

    Just copy/paste the code into the functions.php file of your child theme or a site specific plugin if you use one.

    Cheers

    Jude

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.