GTM tag in _header.php file of child theme not loading anymore

A few years ago I added Google Tag Manager tag to the _header.php file of the X Pro child theme, i.e. this file framework/views/global/_header.php, and then promptly forgot about it because it worked fine.

That was until 6-weeks ago when it seems like the _header.php file stopped being used and as a consequence the GTM tag stopped being loaded on the site.

Around the same time I re-built the global nav using the Header Builder that’s available in Pro. So I have a few questions:

  • Does creating a custom header assigned to all pages mean that the _header.php file is no longer used / loaded? Or is the issue related to something else?
  • To fix the problem, I’ve loaded the GTM tag via the functions.php file of the child theme using the wp_head hook and it seems to be working. Is it best practice to load tags like the GTM tag via the functions.php file? Or should I be using a different method?

Any info you can provide as to why this issue occurred would be much appreciated.

Brendan

Hi Brendan,

The best way to add the GTM codes is through the hooks in the functions.php of your child theme. Or else you can add the JavaScript code using the following plugin

https://wordpress.org/plugins/insert-headers-and-footers/)

Hope it helps.
Thanks

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