How to redirect new WordPress user to previous page after registering

When a user registers for a WordPress site, they are redirected to the login page after completing the registration form. Is there a way to redirect them to the previous page before filling out the registration form?

Please note that I’m not looking for a custom/static page because the user will be coming from various pages and that’s the page I want them to return to – not the same page for every case. Thanks!

Related posts

1 comment

  1. There’s a registration_redirect filter you can use:

    add_filter( 'registration_redirect', 'wpse_129618_registration_redirect' );
    function wpse_129618_registration_redirect( $redirect ) {
        if( isset( $_SERVER['HTTP_REFERER'] ) && 0 != strlen( $_SERVER['HTTP_REFERER'] ) ) {
            $redirect = esc_url( $_SERVER['HTTP_REFERER'] );
        }
        return $redirect;
    }
    

    Alternately, you can edit the PHP that is generating your <form> and add a hidden field named redirect_to, using the current page’s address (ie, $_SERVER['PHP_SELF']).

    References

Comments are closed.