[Resolved] Google Tag Manager

Home Forums Support [Resolved] Google Tag Manager

Home Forums Support Google Tag Manager

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
  • #463674

    I’ve used the search, but there are different answers on this. Just to be sure, is that how you add the two different parts of the Google Tag Manager code:

    1. The code that goes as high in the <head> of the page goes here:

    “wp_head” in the GP Hooks

    2. The code that goes immediately after the opening <body> tag goes here:

    “Before Header” in the GP Hooks


    GeneratePress 2.0.1
    Customer Support

    Hi there,

    Both correct 🙂



    I got three question about this too:

    1) When using the hooks as described above, do I guess correctly that I will not need a WP plugin such as this one anymore, because the 2 hooks will take care of the correct implementation of the 2 GTM codes? I am actually also using the Google Analytics Dashboard for WP (GADWP) plugin which also offers me to connect to connect with GTM, but I don’t know if this is automatically taking care of implementing both tracking scripts that are necessary for GTM.

    2) The GTM code that needs to go “immediately after the opening <body> tag”: In my “Before Header” hook I see already some code:

    Is it OK to add the GTM code after that, or do I have to add it before that other ‘full container’ code, since it talks about “immediately”?

    3) I have another code (Mixpanel) that I need to add in connection with GTM. It says: “Paste this snippet just before the </head> tag of your page”. Do I assume correctly that I need to add that under the “After Header Content” hook then? Or is “before the </head> tag” another hook?

    Your answer will be much appreciated.

    Kind regards


    Hi Edin and David! I had this issue before, but since GP 2.0 Tom created a little snippet that you can add via your functions.php file or via a plugin like Code Snippets.

    add_action( 'generate_before_header', 'tu_add_google_tag_manager', 0 );
    function tu_add_google_tag_manager() { ?>
        Here goes the GTM code
    <?php }

    And there you go, your GTM is ready to work!


    Hi Roverd

    Thank you for your answer.

    Do I assume correctly that I can/should change the “tu” prefix to something of my own? I remember reading today this quick knowledge base entry where Tom says he’s using “tu” based on his initials:

    Logically, this will not make any difference, but I just wanted to ask it, to avoid that the code breaks if indeed I adjust that from “tu” to something of my own.



    PS: Do you happen to have an answer for my question #3 as well?


    Hi David,
    Code that you need to show inside the <head></head> tag of your site will go into the “wp_head” hook of GPP.
    As a reference you can take a look at GP hook locations here:
    http://demo.generatepress.com/hook-locations/ (The wp_head hook is not mentioned in this link)
    The “wp_head” hook, like the “wp_footer” hook are intended for adding JS, tracking codes, etc…
    The other hooks can be used to actually display content on your site.

    Hope this helps,


    Thank you, Dan! I must have been tired yesterday evening to not understand that ‘before the </head>’ means inside the <head>’… duh… 🙂

    Lead Developer
    Lead Developer

    David – you can absolutely change the function prefix, but you have to change it in both places (add_action() and the function).

    I use tu_ as they’re my initials 🙂


    Thank you, “TU” 🙂

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