How to Change URL After Submitting the Form Successfully
To change the URL after submitting the form successfully can be easy by using the right WordPress function. In this case, we will be using “wp_redirect()” function that allows to set URL to which we should be redirected after successful form submit.
For example, we would like to redirect visitors to the specific page after they submit a contact form. So we should use “wp_redirect()” function at the end of form submit code. Considering that contact form is sending the email after submitting it, the complete code should look like this:
1 2 3
wp_mail($emailTo, $subject, $body, $headers); $emailSent = true; wp_redirect( 'URL', 301 ); exit;
Please note, replace ‘URL’ with the link to the page to which visitors will be redirected. As we can see this function can be used to redirect visitors after submitting the contact form to the page which would show let’s say “Thank you for contacting us, we will respond shortly.” Of course, it can be used anywhere it might be useful.