apply_filters ( 'grunion_contact_form_redirect_url', string $redirect, int $id, int $post_id )

Filter the URL where the reader is redirected after submitting a form.

Source file: modules/contact-form/grunion-contact-form.php

View in GitHub

Parameters

$redirect

(string) Post submission URL.

$id

(int) Contact Form ID.

$post_id

(int) Post ID.


Changelog

Since: Jetpack 1.9.0


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 );

Have a note to contribute?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s