-
AuthorPosts
-
July 18, 2018 at 7:03 pm #987140
Greetings,
I’m troubling shooting the best way to setup my google tag manager in my header.php. I activated a child theme and trying to figure out the best way about going about this. I have included the header.php file with the tags. Can i just add this file to the child theme root and it will work?
Regards,
July 18, 2018 at 8:20 pm #987163Hi,
Moving header.php file to your child theme should not be necessary. Please refer to this post – https://kriesi.at/documentation/enfold/add-custom-js-or-php-script/#add-a-script-to-head-section and add your tags using functions.php file of your child theme.
Regards,
YigitJuly 18, 2018 at 8:34 pm #987166Thanks Yigit,
Interesting, this is a little above my coding knowledge… Given the file in the private section can you advise further? I have tried several plugins to add the google tag manager but non seem to work properly given where the code needs to be placed.
July 19, 2018 at 6:45 pm #987575Hi,
You can try to follow this tutorial: https://www.wpbeginner.com/beginners-guide/how-to-install-and-setup-google-tag-manager-in-wordpress/ and use this plugin: https://wordpress.org/plugins/insert-headers-and-footers/ to add custom scripts to the head section without coding. Setting up the google tag manager is beyond the scope of our support forum and you may need to hire a developer if you’re not familiar with the implementation of google tags.
Best regards,
DudeJuly 20, 2018 at 1:16 am #987665Hello Dude.
I have actually already tried that solution but from what I see a few people on the forums can’t get this to work with insert head and footers solution. I’ve actually tried a few google tag mangers plugins with the Enfold theme without any luck.
July 21, 2018 at 8:34 pm #988211Hi mesagaragedoors,
Can you show us the code that you’re trying to add?
Best regards,
VictoriaJuly 24, 2018 at 10:48 pm #989409Here is the code (See Private)
July 25, 2018 at 2:15 pm #989695Hi mesagaragedoors,
Yes, if you want to keep this code in the header file, you need to copy it to the child theme and you will need to update it manually everytime you update the theme.
Or you can use the codes to add in the functions.php, it is a cleaner way and requires less maintenance.
If you need further assistance please let us know.
Best regards,
VictoriaJuly 25, 2018 at 5:27 pm #989823Hi Victoria,
The problem is when I use the codes to add in the functions.php the code does not work with the enfold theme.
July 25, 2018 at 5:51 pm #989837Hi,
Please try adding following code to bottom of Fuctions.php file in Appearance > Editor
Best regards,
YigitJuly 25, 2018 at 8:03 pm #989907Ahoy Yigit,
Would this be in the child theme functions.php? Do I need to do anything else? Right now I do not have https://wordpress.org/plugins/insert-headers-and-footers/ to add custom scripts instead seeing it wasn’t working. I uninstalled it. The problem is when I used it with ENFOLD it didn’t work.
July 27, 2018 at 8:45 am #990574Hi,
You need to add it to the child theme funtions.php file (i.e. at the very bottom). Yigit’s code contained some invalid quote characters (I think the forum script converted them accidentally) – please use this code instead:
//------------------------------- // Google Tag Manager script in head section //------------------------------- function av_google_tag_head(){ ?> <!– 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','GTM-THXCK3T');</script> <!– End Google Tag Manager –> <?php } add_action('wp_head', 'av_google_tag_head'); //------------------------------- // Custom script in body //------------------------------- function av_google_tag_body(){ ?> <!– Google Tag Manager (noscript) –> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-THXCK3T" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!– End Google Tag Manager (noscript) –> <?php } add_action('wp_footer', 'av_google_tag_body');
You also need to check the google tag manager id. At the moment it’s set to GTM-THXCK3T in the code above (two occurrences) but you may need to replace it with your id, otherwise the code won’t work.
Best regards,
Dude -
AuthorPosts
- You must be logged in to reply to this topic.