Filter the URL where the reader is redirected after submitting a form.
Parameters
- $redirect
string Post submission URL.
- $id
int Contact Form ID.
- $post_id
int Post ID.
Changelog
- Introduced in Jetpack 1.9.0
How to use this hook
Notes
This filter allows us to set different redirection URLs for each form on your site. Here is an example:
/**
* Jetpack Contact Form Custom Redirections.
*
* @param string $redirect Post submission URL.
* @param int $id Contact Form ID.
* @param int $post_id Post ID.
*
* @return string $redirect Custom Post submission URL.
*/
function jetpackcom_custom_form_redirect( $redirect, $id, $post_id ) {
/**
* Create a list of pages where you've inserted forms.
* For each contact Form ID (found via the id attribute on the form),
* set up a custom URL where the user will be redirected.
*/
$redirects = array(
'1370' => home_url( 'page_on_your_site' ),
'2239' => home_url( 'another_page' ),
'1370' => home_url( 'page_on_your_site' ),
);
// Let's loop though each custom redirect.
foreach ( $redirects as $origin => $destination ) {
if ( $id == $origin ) {
return $destination;
}
}
// Default Redirect for all the other forms.
return $redirect;
}
add_filter( 'grunion_contact_form_redirect_url', 'jetpackcom_custom_form_redirect', 10, 3 );