Skip to content

Instantly share code, notes, and snippets.

@zeshanshani
Created February 17, 2017 21:38
Show Gist options
  • Save zeshanshani/714cf3a3fa57b206989634ac5443dba2 to your computer and use it in GitHub Desktop.
Save zeshanshani/714cf3a3fa57b206989634ac5443dba2 to your computer and use it in GitHub Desktop.
Redirect CF7 After Submission using PHP action hook.
/**
* Redirect CF7 After Submission
*
* Accepts 'custom_on_sent_ok' parameter in CF7 form additional settings. e.g.,
* custom_on_sent_ok: http://example.com/thank-you
*/
add_action( 'wpcf7_mail_sent', 'custom_redirect_cf7_form' );
function custom_redirect_cf7_form( $wpcf7 ) {
$on_sent_ok = $wpcf7->additional_setting('custom_on_sent_ok', false);
if ( is_array( $on_sent_ok ) && count( $on_sent_ok ) > 0 ) {
wp_redirect( trim( $on_sent_ok[0] ) );
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment