Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1214576
    Benjamin
    Participant

    Hello,

    I am trying to get my Google tag manager code be placed correct but I get the above warning from the tag assistant.
    I have my analytic code working but not tag manager code. Below it the code as it is in the functions.php file in my child theme.

    // =============================================================================
    function add_google_tag_manager_code(){ ?>
    
    <!-- Google Tag Manager -->
    <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-KHG89S"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <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=
    '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-KHG89S');</script>
    <!-- End Google Tag Manager -->
    
    <?php }
    
    add_action( 'wp_head', 'add_google_tag_manager_code' );
    
    // End Add Google Tag Manager Code
    // =============================================================================

    Can you see any mistakes here?

    Best regards,
    Ben

    #1214871
    Rupok
    Member

    Hi Ben,

    You are adding it in right way so it should work fine if the code is correct. Let’s check the source code to make sure it was added.

    Cheers!

    #1215360
    Benjamin
    Participant

    Hello Rupok,
    Yes that above code looks good when comparing source.
    Although, when checking in my Google tag manager admin, I see that there is additional code which needs to be added also and this code needs to be placed immediately after the opening <body> tag:

    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KHG89S"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->

    Could you help me to implement this code in my functions.php file?

    Cheers,
    Ben

    #1215702
    Rupok
    Member

    Hi Ben,

    You have placed the other code within wp_head. So you can use the same step to add within wp_footer.

    Also there is a plugin to add scripts within header and footer – https://wordpress.org/plugins/insert-headers-and-footers/

    Using script to header and footer is usual. If you need to add anything within the body, you can try RAW Content element within page content.

    Hope this makes sense.

    #1217030
    Benjamin
    Participant

    Ok thanks Rupok,

    Appreciate your time. Will have a look.

    Cheers,
    Ben

    #1217075
    Friech
    Moderator

    Let us know how it goes,

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-1214576 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>