Contact form 7 redirect not working and How to set redirections – All Solved

That’s an issue I am seeing everywhere in blogs and support forums. A common problem with Contact Form7 though it has so many solutions. Still it has many confusion? Cause Contact form 7 plugin can have multiple forms and wrong placement of the codes can redirect all forms to a single thank you page, But if you want different thank you page or destination page for each form ? That’s only one scenario I am talking. For Non-Coder people that’s a huge frustration how would they do it? With a popular plugin like contact form 7 everyone thought it would be available. Actually, it is but with another plugin. All issues I am solving here one by one for everyone.

First Solution for non-coder people or who just can use plugins in WordPress.

Don’t go right or left just straightforward use this plugin. The name is Contact Form 7 Redirection, click here to download.

After installind Contact Form7 Redirection plugin, you will have the option to redirect your every form to your desired page or link. Inside your form settings like the image below a new tab will appear called Redirect Settings. Set your URLĀ  where you want them to redirect after submission. Just like a piece of cake.

Contact form 7 redirect not working

 

Now if this option, in any case, doesn’t work, we have to go manually through coding. Now I will show you how to do it. Don’t afraid I believe everyone will be able to do it who don’t know coding also.

1. First, we will use a code which will redirect all of our forms to a selected single thank you page or destination page. The code is given below

 

[pastacode lang=”javascript” manual=”%3Cscript%3E%0Adocument.addEventListener(%20’wpcf7mailsent’%2C%20function(%20event%20)%20%7B%0Alocation%20%3D%20’http%3A%2F%2Fexample.com%2F’%3B%0A%7D%2C%20false%20)%3B%0A%3C%2Fscript%3E” message=”” highlight=”” provider=”manual”/]

 

*** replace your URL with http://example.com ***

To use this code open your theme’s header.php file. Who knows how to use ftp or cpanel’s file manager just navigate to your theme’s folder and open your theme’s header.php file to edit.

or those are afraid of these things just go to website’s dashboard -> appearance -> Editor and open your theme’s header.php file

Now as I showed below with the image. Place the code before </head> tag.

Now if you try you will see all of your forms will redirect to a single thank you page.

2. Now if you want each form to redirect individual page or URL use the code below.

[pastacode lang=”php” manual=”add_action(%20%E2%80%98wp_footer%E2%80%99%2C%20%E2%80%98cf7_thank_you_redirect%E2%80%99%20)%3B%0A%0Afunction%20cf7_thank_you_redirect()%20%7B%0A%3F%3E%0A%3Cscript%20type%3D%E2%80%9Dtext%2Fjavascript%E2%80%9D%3E%0Adocument.addEventListener(%20%E2%80%98wpcf7mailsent%E2%80%99%2C%20function(%20event%20)%20%7B%0Aif%20(%20%E2%80%988%E2%80%99%20%3D%3D%20event.detail.contactFormId%20)%20%7B%0Alocation%20%3D%20%E2%80%98http%3A%2F%2Fexample.com%2Ffirst%E2%80%99%3B%0A%7D%20else%20if%20(%20%E2%80%984%E2%80%99%20%3D%3D%20event.detail.contactFormId%20)%20%7B%0Alocation%20%3D%20%E2%80%98http%3A%2F%2Fexample.com%2Fsecond%E2%80%99%3B%0A%7D%20else%20%7B%0A%2F%2F%20do%20nothing%0A%7D%0A%7D%2C%20false%20)%3B%0A%3C%2Fscript%3E%0A%3C%3Fphp%0A%7D” message=”” highlight=”” provider=”manual”/]

you have to use this code in your theme’s functions.php file. Just like the screenshot below.

Here I have shown two redirection for two forms. If you have more than two forms just increase the else if part. My two forms id was 8 and 4 , Get your forms ids and replace with 8 or 4 also replace URLS with your own links instead of example.com.

How to get your contact form ids ? Just check the below image.

That’s it , I hope you guys will be helped with my blog. Please share or subscribe and if you want premium service we are open for 24/7 support. Thanks

Leave a Comment