Contact Form 7 Thank You Page Redirects

WordPressPosted on

1 min read

CF7 is a cool contact form plugin, so it is operating fully on JavaScript (if enabled) when it comes to sending messages. If we send a message through it, we stay on the same page by default which is proper behavior.

Sometimes we want to redirect to another page after sending like a “Thank you!” page. We can do this the help with JavaScript events.

document.addEventListener( 'wpcf7mailsent', function( event ) {
   if ( '101' == event.detail.contactFormId ) {
      location = 'https://www.example.com/thank-you-page-one/';
    } else {
      location = 'https://www.example.com/thank-you-page-two/';
    }
}, false );

Add the code into one of your script file or into the site’s footer with wp_footer filter between <script></script> tags. You can also catch different form by id too.

Note: if you want to use a “Thank you!” page just for tracking conversion or any analytics you don’t need a redirect, you can use the event to trigger the proper code.

Need a web developer? Maybe we can help, get in touch!

Similar Posts

More content in WordPress category