Redirect user to previous page after signup from custom form
I've looked on here and found lots of references to this, but none have worked for me, probably because there must be something in the custom code I am modifying that I don't quite understand. Having taken data from pervious posts here is the original parts of the code that I think I needed to modify: Line 124
// Only show the registration form to non-logged-in members.
if ( ! is_user_logged_in() ) {
add_action( 'wp_footer', 'wyz_add_pass_strength_script' );
There is then a large amount of code for the sign up form which results at the end in the following Line 739
$creds = array();
$creds['user_login'] = $registration_data['user_login'];
$creds['user_password'] = $registration_data['user_pass'];
$creds['remember'] = true;
$user = wp_signon( $creds, is_ssl() );
$url = apply_filters( 'wyz_after_login_redirect', home_url( '/user-account/' ), $user, true );
$url = apply_filters( 'wyz_after_register_redirect', $url, $user );
// Send the newly created user to the user account page after logging him in.
wp_redirect( $url );
exit;
The current code takes the user to the account page as stated in the code comment. I want to take the user back to the original page so I added
$redirect = home_url() . '?redirect_to=' . esc_url($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
At Line 126 And modified to
wp_redirect ($redirect)
before the exit. It didn't work. I kinda expected it wouldn't but I'm not sure what to do now. I've left out the rest of the code because I wanted to keep this query succinct, but if it's required, please let me know and I'll edit the post.