• Hi. Is it possible to redirect a user after logging in to the referring website (not page). For example, user visited example.com and clicked on a link there, and it took the user to the WordPress website: test.com/login, and after user logs in, redirect them back to example.com

    • This topic was modified 2 years, 7 months ago by Jan Dembowski.
Viewing 1 replies (of 1 total)
  • My suggestion would be the following code for this:

    function wpdocs_my_login_redirect( $url, $request, $user ) {
    	if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
            if( !empty($_REQUEST['redirect_to']) ) {
    	        wp_redirect($_REQUEST['redirect_to']);
                exit;
            }
    	}
    	return $url;
    }
    add_filter( 'login_redirect', 'wpdocs_my_login_redirect', 10, 3 );

    This ensures that a redirect to the URL specified in redirect_to happens after login. To do this, the login form must be called as follows: https://wordpress4.local/wp-login.php?redirect_to=http%3A%2F%2Fgoogle.de%2F&reauth=1 – here the desired target URL must be specified in redirect_to.

Viewing 1 replies (of 1 total)
  • The topic ‘Redirect WordPress Back to Referring Page After Login’ is closed to new replies.