If you have a contact form on your website, it’s important to let your visitors know that their message has been successfully sent. One way to do this is by redirecting them to a thank you page after they submit the form. In this article, we will show you how to redirect Contact Form 7 to a thank you page using a simple code snippet.
Step 1: Install and Activate Contact Form 7
If you haven’t already, install and activate the Contact Form 7 plugin. You can find it in your WordPress dashboard under Plugins > Add New.
Step 2: Create a Thank You Page
Create a new page on your website that will serve as the thank you page. Give it a title and add any content you want to display after the form is submitted.
Step 3: Add Code Snippet to Functions.php File
Open your theme’s functions.php file in a text editor or code editor. Add the following code snippet at the bottom of the file:
add_action( 'wpcf7_mail_sent', 'my_contact_form_sent' );
function my_contact_form_sent( $cf7 ) {
wp_redirect( get_permalink( 123456 ), 301 ); exit;
}
Replace the number “123456” with the ID of your thank you page. You can find the ID by going to Pages > All Pages and hovering over the page title. The ID will be displayed in the URL.
Step 4: Save Changes
Save your changes to the functions.php file and upload it back to your server using an FTP client or through your WordPress dashboard.
Conclusion
By following these simple steps, you can redirect Contact Form 7 to a thank you page on your website. This will help improve the user experience and let your visitors know that their message has been successfully sent.