Troubleshooting //
Fail to Configure the Redirect Action Hook

Fail to Configure the Redirect Action Hook

Question

I’m not sure how to use the Call a Hook functionality to redirect a user to a certain page

Answer

The Redirect to Page post-submit action redirects to the internal pages on your website according to security reasons. But with the Call a Hook action, you can redirect users to external sites.

Hooks can be called “actions” in other words. You create an action using HTML code and insert it into your theme’s functions.php file. Upon the Form submission, if the hook inserted into a corresponding field matches the code in functions.php, the action is performed.

Let’s consider the following example:

call a hook notification type settings


Here is the hook where “redirect” is the Hook name, and you can insert your own one based on the tips below this field.

After that, this code should be inserted into functions.php of your active theme:

add_action( 'jet-engine-booking/redirect', function() {
   wp_redirect( 'https://wordpress.org/' );
    exit;
}
);

Go to Appearance > Theme Editor and press the Theme Functions (functions.php) tab in the right-side section. Scroll down the theme contents a bit and paste the code in there. Then update the file.

functions.php editing and code input


This hook means that upon form completion you will be redirected to https://wordpress.org/.

Another example would be redirected to URL from the form field only if the user has chosen the option to redirect.

add_action( 'jet-engine-booking/redirect', function( $data ) {
if ( $data[ 'redirect' ] == 'true' ) {
   wp_redirect( $data[ 'page_url' ] );
    exit;
}
}
);

Here is the hook where ‘redirect’ can be radio or checkbox field and ‘page_url’ can be text or the hidden field with the page URL.

The Call a Hook functionality requires developer skills and knowledge in order to create the necessary actions. You can learn more from here: https://developer.wordpress.org/plugins/hooks/.

Was this article helpful?
YesNo
Still need help?
Submit a request