Tagged: x
-
AuthorPosts
-
October 19, 2016 at 3:39 pm #1222820
metamediaParticipantHi,
I am trying to properly install a Google Tag Manager code. I searched the forum and found this code to install in my child theme’s functions.php section:
—————-
function my_custom_head_output() {
?>
<!– 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-W3PT5X’);</script>
<!– End Google Tag Manager –>
<?php
}add_action( ‘wp_head’, ‘my_custom_head_output’, 99999 );
function my_custom_footer_output() {
?>
<!– Google Tag Manager (noscript) –>
<noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-W3PT5X”
height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
<!– End Google Tag Manager (noscript) –>
<?php
}add_action( ‘wp_footer’, ‘my_custom_footer_output’, 99999 );
———–
However, that I keep getting the following error messages when testing with the Google tag assistant:
“HTTP response code indicates tag failed to fire: Status 404. This could be due to an empty or un-published container”
“Code found outside of <body> tag” message”Any ideas on how to fix this? Thanks!
metamediacreative.com
October 19, 2016 at 6:19 pm #1222989
metamediaParticipantDisregard this post. I overlooked that I had not yet published GTM. It appears to be working correctly now.
October 19, 2016 at 6:22 pm #1222991
metamediaParticipantRe-regard this post. I’m still getting the “Code found outside of <body> tag” message.
October 19, 2016 at 10:17 pm #1223291
RadModeratorHi there,
It is outside, since you added it through wp_head which is outside the <body> tag. Please change this line
add_action( 'wp_head', 'my_custom_head_output', 99999 );to this,
add_action( 'x_before_site_begin', 'my_custom_head_output', 99999 );Hope this helps.
October 20, 2016 at 8:46 am #1223880
metamediaParticipantI copied and pasted your line and now get:
Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /home/metamedi/public_html/wp-content/themes/x-child/functions.php on line 40
October 20, 2016 at 9:18 am #1223913
metamediaParticipantLine 40 is:
function my_custom_footer_output() {
?>It broke the front end, so I had to change it back.
October 20, 2016 at 10:22 am #1224018
metamediaParticipantI found the following code in a thread:
// Add Google Tag Manager Code
// =============================================================================
function add_google_tag_manager_code(){
?><!– Insert Google Tag Code starts here –>
<!– Insert Google Tag Code ends here –>
<?php
}
add_action( ‘x_before_site_begin’, ‘add_google_tag_manager_code’ );
// End Add Google Tag Manager Code
// =============================================================================It appears to work. Thanks!
October 20, 2016 at 10:36 am #1224038
RahulModeratorGlad you’ve sorted it out for yourself.
Let us know if you need any further help with the theme!
Thanks!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1222820 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
