Archived topic
Possible compatibility issue b/w GP and Google Tag Manager for WP
15 replies · Started by Dragomir on February 25, 2018
Dear Tom,
I initiated a discussion with the Thomas Geiger, the developer of the wonderful "Google Tag Manager for WP" plugin - the discussion is related to an issue with placing the GTM code in the <body> tag when using GeneratePress.
I would like to ask you if you could chime in and check if the assumptions there are correct - your opinion could bring additional light to the subject.
You can find the topic here - https://wordpress.org/support/topic/bug-body-part-is-not-written-when-get_body_class-is-called-twice/
Thank you in advance and best regards,
Drago
Hi there,
No need to a plugin to insert GTM:
https://generatepress.com/forums/topic/google-tag-manager-gtm/#post-486806
https://docs.generatepress.com/article/hooks-overview/
Hi Leo,
The Google Tag Manager for WP plugin does not only insert the GTM tags into the page, it does a lot more.
You can read more here:
It's a good plugin and I would very much like to use it, as long as the compatibility issue is resolved.
Leo, did you have the chance to read the thread I am referring to? Do you think the issue might be resolved?
Thank you and best regards,
Drago
Just replied to the WP.org topic :)
Thanks a lot, Tom :)
No problem :)
I read this thread and i am still stumped on what to do. Tag assistant by chrome extention is showing errors for me stating its not installed properly. I have clicked custom and not put in any code in to the hooks.
An error occured while the tag was fired: net::ERR_ABORTED
Error while sending request: net::ERR_ABORTED
I use generate press, elementor and elements for the hooks.
I made an error. Just leave the hook blank and it works fine.
Hi Tom and Dragomir,
Many thanks for this discussion and the link to the Wordpress.org discussion on this subject. I presume you are referring to this exchange:
https://wordpress.org/support/topic/bug-body-part-is-not-written-when-get_body_class-is-called-twice/
Can you please advise whether we have added the code correctly that Tom Geiger refers to in the setup of his plugin. You can see his instruction here in this screenshot:
https://i.imgur.com/hVncGAQ.png
This is what we have added to the functions.php file of our GeneratePress Child Theme:
//* DuracellTom Google Tag Manager & GeneratePress
add_action( 'generate_before_header', function() {
if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); }
}, 0 );
Alternatively, would you recommend that we use the 'Codeless Injection'? We have tried it and it does not seem to break our site at the front end.
I look forward to your recommendation.
Kind regards,
Pairfum London
https://www.pairfum.com
That code looks like it should work. Alternatively, you can use a Hook Element.
The codeless injection should work as well, as long as the fix the author implemented is still working.
Hi Tom,
Many thanks for your advice.
We have tried the code snippet and it seem to work.
I am glad to hear that you believe the codeless injection works too. It seems to work when we tried but we did not test it extensively.
Many thanks for your help.
Kind regards,
Pairfum London
https://www.pairfum.com
Sorry for re-opening this thread, Tom.
I was having another look at how best to add code and your suggestion of adding a new a Hook Element:
- code: I literally just paste this code snippet into the content area
if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); }
This snippet is from the screenshot further above in this tread.
- hook: before_header
- execute php: ticked
- priority: zero
- display rules > location > entire site
Can you confirm that you believe this looks like it will work?
The plugin author was not very clear about the compatibility fix being still in place and your hook element suggestion seems safer to me in the long run.
The plugin author did confirm, however, that he believes the codeless injection should work with GeneratePress.
Many thanks for your help.
Kind regards,
Pairfum London
https://www.pairfum.com
I'd go like this:
<?php
if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); }
?>
Hi Leo,
Many thanks for your reply & recommendation.
Just to double-check with you on the location of the hook:
before_header is the equivalent to "just after the opening body tag", as outlined in the screenshot above?
Interesting that you keep <?php and ?> - I thought that ticking 'execute php' would do this.
Many thanks for your help on this.
Kind regards,
Pairfum London
before_header is indeed just after the opening of body tag:
https://github.com/tomusborne/generatepress/blob/master/header.php#L38
You could also use the newly added wp_body_open hook as well:
https://github.com/tomusborne/generatepress/blob/master/header.php#L27
Hi Leo,
Many thanks for the clarification and the speed of adding the wp_body_open hook. Impressive!
Kind regards,
Pairfum London
https://www.pairfum.com