Help with Javascript in Custom JS

I have been asked to add a pixel tracking marketing script to a website and need help adding it since you cannot put the script tags into the Custom JS. Can anyone help me convert this or explain where I can put it? I tried putting it in the child theme in the header base.php and its not being loaded.

<script language='JavaScript1.1' async src='//pixel.mathtag.com/event/js?mt_id=1338990&mt_adid=208493&mt_exem=&mt_excl=&v1=&v2=&v3=&s1=&s2=&s3='></script>

Hi there,

Thanks for writing in! You can add the above script using wp_head action hook. Try adding the following code in your Child Theme’s functions.php file:

add_action('wp_head','my_tracking_pixel');
function my_tracking_pixel() { 
?>
<script language='JavaScript1.1' async src='//pixel.mathtag.com/event/js?mt_id=1338990&mt_adid=208493&mt_exem=&mt_excl=&v1=&v2=&v3=&s1=&s2=&s3='></script>
<?php 
}

You can learn more about wp_head action hook by visiting the following link https://codex.wordpress.org/Plugin_API/Action_Reference/wp_head

Cheers!

1 Like

Wow thank you so much for this, I will read up on it :slight_smile:

You are most welcome. :slight_smile:

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