Site logo

Archived topic

GPP / Child Theme / DOM Event

5 replies · Started by Jan on March 27, 2021

Viewing posts 1–6 of 6

Hi David,

I need to add the following custom dome event to the function.php of the child theme:

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
  location = 'http://example.com/';
}, false );
</script>

Unfortunately I keep getting an error message saying:

Parse error: syntax error, unexpected '<', expecting end of file in /mnt/web408/e3/19/59617319/htdocs/STRATO-apps/wordpress_01/app/wp-content/themes/generatepresschild/functions.php on line 18

What am I missing?

Thanks,
Jan

Hi there,

thats Javascript and should not be added directly to the Functions.php .... you need to hook the code in place.

Simplest method is to add it using a Hook element:

https://docs.generatepress.com/article/hooks-element-overview/

And select the wp_footer hook.

If you must add it to the functions.php then you would add the hook first eg.

add_action('wp_footer', function() {
   ?>
   // Add your script here
   <?php
});

Many thanks David.

I’ll follow your advice re the hook element and then let you know accordingly.

Regards,
Jan

You're welcome

Hi David,

meanwhile, I was able to successfully test your advice.

Thanks again.

Regards,
Jan

Glad to be of help

This archived topic is closed to new replies.