Tagged: function.php, google ads, google tag manager, tag manager
-
AuthorPosts
-
November 27, 2019 at 11:07 pm #1160823
Hi,
I am trying to add google tag manager, but it seems like I can only add the <head> script in the “google analytics tracking code” box.
Where do I add/paste the <body> script? I.e this script:<!– Google Tag Manager (noscript) –>
<noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-M9R8TKM”
height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
<!– End Google Tag Manager (noscript) –>Thank you in advance!
BR,
EmmaNovember 29, 2019 at 11:40 pm #1161402Hey Emmasfm,
You will need to do this with code, as we do not have an option to add code inside body through our Theme Options.
Best regards,
BasilisFebruary 13, 2020 at 11:35 am #1184108I have the same problem with Emmasfm.
Here are GTM script:
– 1st Script: I copy a header.php from the Enfold into the child theme. And then, I paste the 1st script into between the <head>…..</head>
– 2nd script: I paste after the <body> tagBut when I check the status of Google Assistant Extension, the yellow color before the Google Tag Manager.
The yellow color means that at least one Google Tag has a minor issue and the issue should be addressed, otherwise you might face some tracking discrepancies.
How can I fix it? (You can see more detail in the private content)Enfold should have an article guide everyone about Google Tag Manager, I search any available can’t solve the problem.
February 13, 2020 at 10:04 pm #1184319Hi ezvisa,
Please have a look at the following thread:
https://kriesi.at/support/topic/google-tag-manager-6/If you need further assistance please let us know.
Best regards,
VictoriaFebruary 14, 2020 at 4:49 am #1184372Victoria, Ismael mention about using “wp_header” for put script into header and “wp_footer” for footer.
But can you write full code for me? Because I have lacked the skill in coding.
I very much appreciate that!February 15, 2020 at 7:29 am #1184677Hi ezvisa,
Please post the full code you are looking to add to your site and where it should go and, we’ll give you some functions to use.
Best regards,
RikardJuly 20, 2023 at 12:12 pm #1413830Enfold Child > functions.php
add these lines and change the GTM-Code to your Code.
/**
* Google Tag Manager Head Script
*/
function add_custom_gtm(){
?>
<!– 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-XXXXXXX’);</script>
<!– End Google Tag Manager –>
<?php
}
add_action(‘wp_head’, ‘add_custom_gtm’);
/**
* Google Tag Manager Body Script
*/
function google_tag_manager_body_code() { ?>
<!– Google Tag Manager (noscript) –>
<noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX”
height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
<!– End Google Tag Manager (noscript) –>
<?php }
add_action( ‘ava_after_body_opening_tag’, ‘google_tag_manager_body_code’, 1);July 21, 2023 at 5:07 am #1413902Hi xxtita,
Thanks for sharing the code.
For further information you can check our documentation: https://kriesi.at/documentation/enfold/google-analytics/Best regards,
NikkoDecember 13, 2024 at 3:28 pm #1473582Dear support, @NIKKO @rikard
I’ve been trying to implement the Google Tag Code from Google Ads for hours.
But i get every the error:
Uncaught Error: Undefined constant “‘wp_head’” in wp-content/themes/enfold-child/functions.php:24
Stack trace:
#0 wp-settings.php(672): include()
#1 wp-config.php(104): require_once(‘/var/www/vhosts…’)
#2 wp-load.php(50): require_once(‘/var/www/vhosts…’)
#3 wp-admin/admin.php(34): require_once(‘/var/www/vhosts…’)
#4 wp-admin/theme-editor.php(10): require_once(‘/var/www/vhosts…’)
#5 {main}
thrown
What its wrong???Here is my script
/**
* Google Tag Manager Head Script
*/
function add_custom_gtm(){
?>
<!– 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-ABCDEFGH’);</script>
<!– End Google Tag Manager –>
<?php
}add_action(‘wp_head’, ‘add_custom_gtm’);
/**
* Google Tag Manager Body Script
*/
function google_tag_manager_body_code() { ?>
<!– Google Tag Manager (noscript) –>
<noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-ABCDEFGH”
height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
<!– End Google Tag Manager (noscript) –>
<?php }
add_action( ‘ava_after_body_opening_tag’, ‘google_tag_manager_body_code’, 1);Can anybody help?
December 13, 2024 at 4:14 pm #1473584December 13, 2024 at 4:37 pm #1473587or try this ( replacing your GTM-IDs ) with copy&paste:
i think it is ok to have both in head section
function ava_g_tag_custom_script() { ?> <!-- 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-XXXXX'); </script> <!-- End Google Tag Manager --> <!-- Google Tag Manager (noscript) --> <noscript> <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe> </noscript> <!-- End Google Tag Manager (noscript) --> <?php } add_action('wp_head', 'ava_g_tag_custom_script');
but if you like to have the noscript in body tag:
function ava_g_tag_custom_script() { ?> <!-- 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-XXXXX'); </script> <!-- End Google Tag Manager --> <!-- Google Tag Manager (noscript) --> <noscript> <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe> </noscript> <!-- End Google Tag Manager (noscript) --> <?php } add_action('wp_head', 'ava_g_tag_custom_script');
December 13, 2024 at 4:54 pm #1473588December 13, 2024 at 6:50 pm #1473596Guenni007 so great for your fast help!
Arrr … i don’t usede the code tag …. :(
Sorry total!
Bist Du Deutscher?December 13, 2024 at 7:02 pm #1473597Guenni007,
Yeahhhh!!! Your Code is great. That works great!!!!
function ava_g_tag_custom_script() { ?> <!-- 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-XXXXXXXXX'); </script> <!-- End Google Tag Manager --> <!-- Google Tag Manager (noscript) --> <noscript> <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe> </noscript> <!-- End Google Tag Manager (noscript) --> <?php } add_action('wp_head', 'ava_g_tag_custom_script');
So many thanks for your great help!
I am so happy!
Thanks and regards strumpel
December 13, 2024 at 10:49 pm #1473600Hi,
Glad Guenni007 could help, thank you Guenni007, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Adding google tag manager in Enfold’ is closed to new replies.