[Resolved] Google Tag Manager Code Right After The Body Tag

Home Forums Support [Resolved] Google Tag Manager Code Right After The Body Tag

Home Forums Support Google Tag Manager Code Right After The Body Tag

  • This topic has 15 replies, 5 voices, and was last updated 6 years ago by Tom.
Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #436397
    Satori

    As many of you already know. Google Tag Manager provides two sets of code, one to be in the head and the other to be right below de body tag. First one is easy to install, but the second one is hard to accomplish for non-techies like me.

    Luckily it seems that in GP 2.0 we can enable this through some magic code. So Tom, show me your magic!

    #436553
    Leo
    Staff
    Customer Support

    Hi there,

    The Before Header hook should be what you are looking for: https://docs.generatepress.com/article/hooks-overview/

    #436630
    Satori

    Hi Leo, thank you. It actually cannot display a particular GTM script. But I was told by Tom himself that there does exist a new solution for this on GP 2.0.

    #436658
    Tom
    Lead Developer
    Lead Developer

    In GP 2.0, you can do this:

    add_action( 'generate_before_header', 'tu_add_google_tag_manager', 0 );
    function tu_add_google_tag_manager() { ?>
        Code in here
    <?php }
    #436691
    Satori

    It didn’t work. Take a look at the screenshots: https://imgur.com/a/jEijE

    This Google Tag Manager thing is driving me crazy.

    #436692
    Tom
    Lead Developer
    Lead Developer

    You would add that function using one of these methods: https://docs.generatepress.com/article/adding-php/

    #436695
    Satori

    Done, thank you so much Tom!

    #437071
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

    #546925
    Steffen

    Hi, I tried to verfiy my site with GTM and used the methods you are talking about but Google is still saying that the GTM is not in the correct position in my website. My Tags in Tag Manager like Analytics are running but it seems to be something wrong.

    https://www.travindr.de

    #547416
    Leo
    Staff
    Customer Support

    Hmm so you’ve added the two parts of code, first part in wp_head and second part in before header hook?

    #547478
    Steffen

    yes and also added the php

    add_action( ‘generate_before_header’, ‘tu_add_google_tag_manager’, 0 );
    function tu_add_google_tag_manager() { ?>
    2nd TGM Code
    <?php }

    #547946
    Tom
    Lead Developer
    Lead Developer

    The function you posted is the correct way to do it.

    I see you’re using a caching or minifying plugin – have you tried clearing it to make sure the code is showing up?

    #547976
    Steffen

    Ahh okay, now it is working. Thanks.

    #548351
    Tom
    Lead Developer
    Lead Developer

    No problem ๐Ÿ™‚

    #557321
    John

    i have done exactly as Steffen has stated above but I am still getting this message when I check it with google tag chrome extension “GTM no-script code not found: either missing or not in <body>”

    google tag manager code in hooks section

    http://www.everytip.co.uk. Any ideas? Cache has been cleared

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.