Redirect WordPress back to Referring Page after Login


Add the following code inside the functions.php file of the theme.

add_filter( 'login_redirect', function ( $redirect_to, $requested_redirect_to ) {
if ( ! $requested_redirect_to ) {
$redirect_to = wp_get_referer();
}
return $redirect_to;
}, 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *