I think I managed to add the applicable code just after the <body> tag by copying the header.php to the child theme folder and editing it. I then used the following in the functions.php:
function hook_googletags() {
?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','xxxxxxxx');</script>
<!-- End Google Tag Manager -->
<?php
}
add_action('wp_head', 'hook_googletags', 0);
The Google Tag code is inserted i the middle of the <head> section. How could I add the code just after the opening <head> tag? Priority 0 didn’t work.
-
This reply was modified 6 years, 9 months ago by
Argentum.