Editing Header to add javascript fonction

Hello,

I’m using the X Theme and the Contact Form 7 plugin. Since the on_sent_ok became obsolete, I have to add the following javascript function ro redirect after submission. I have to add it in the header.php but I can’t seem to edit it properly since I don’t see the entire code when I go in the Editor of the theme.

Here’s the javascript I wanna add.

< script type=“text/javascript”>
document.addEventListener( ‘wpcf7mailsent’, function( event ) {
location = ‘YOUR URL’;
}, false );

Here’s what I see when I go to the theme editor

Thanks

Hi There,

Thanks for writing in!

Please use Child theme to add any custom js code, to avoid any issue in future updates.
Please check this article

How to add custom script via function file. You can use child theme function file to Enqueue the script in header.

Hope this helps.

Thanks

Hi There,

Try adding your Javascript code directly into your Cornertone’s custom Javascript area without <script> tags.

document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'YOUR URL';
}, false );

Or else, you can try following the below method and add it into your child theme’s functions.php file.

add_action('wp_head','custom_javascript');
function custom_javascript () { ?>

<!-- Replace this with your javascript code -->

<?php }

Hope that helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.