How do I add javascript to the head of the page?

Hi,

I am trying to work out how to add some tracking code between the head tags of each page. I have searched the forum but can’t seem to find a solution after 2014 and think the framework folders may be slightly different now.

Where do I need to insert the tracking code so that it appears between the head tags?

Hi There,

Please add this code under functions.php file locates in your child theme:

add_action( 'wp_head', 'print_custom_script', 999 );
function print_custom_script(){
	?>
	<script>
	/* your script will go here */
	</script>
	<?php
}

Hope it helps :slight_smile:

Perfect!! Thanks for the speedy reply!

You’re welcome.

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