Archived topic
WPcode light
22 replies · Started by Michael on February 1, 2023
The Google ads support team asked me to install the WPcode light plugin to add some header and footer code. However, the plugin didn't work. Is this because there might be a conflict between the plugin and generatepress? Is there another way to add code to all headers and footers?
Thanks,
Michael
Hi there,
The hook element would be what you are looking for:
https://docs.generatepress.com/article/hooks-element-overview/
https://docs.generatepress.com/article/wp-head/
https://docs.generatepress.com/article/wp_footer/
Let me know if this helps :)
I regret I need more help on this:
(It's Google code to track Google ads)
I need to add this code in the Global head section of the website above the closing head tag </head> :
https://jsfiddle.net/4Lh7zvkn/
Additionally, paste the code in the Global footer section of the website above the closing body tag </body>:
https://jsfiddle.net/yfzb86gL/3/
Can you give me more specific instructions on how to do this? I haven't managed to get this from the articles you referenced
Michael
Hi there,
1. go to Appearance > GeneratePress and Enable the Elements Module.
2. in Appearance > Elements -> Add New --> Hook Element.
https://docs.generatepress.com/article/hooks-element-overview/
3. In the Text Area paste in the code that you need to add before the </head> tag.
4. Set the Hook to: wp_head
5. Set the Display Rules to Entire Site
6. Publish that element.
Then repeat the above steps from step 3 for the second code, changing these points:
3. In the Text Area paste in the code that you need to add before the </body> tag.
4. Set the Hook to: wp_footer
Thanks that looks great,
I've added and published, however, a question on reflection:
I didn't give the hook a name; does that matter,
Michael
It doesn't matter, as WP will just create a no title slug for it.
But you can go back and edit the element, and give it a title for future reference.
Unfortunately, https://jsfiddle.net/4Lh7zvkn/ is now viable at the top of every page (for a viewer) and Google says the tags aren't firing), can you tell me what I've done wrong?
Michael
The site is https://nlp-training.org/
Hi Michael,
What's the exact code you pasted in the hook element?
This was the full instructions from Google
(I'll have a look to see if I've made any obvious errors)
Paste the code in the Global head section of the website above the closing head tag </head> :
https://jsfiddle.net/4Lh7zvkn/
(Please click on the above mentioned link to access the code )
Additionally paste the code in the Global footer section of the website above the closing body tag </body>:
https://jsfiddle.net/yfzb86gL/3/
(Please click on the above mentioned link to access the code )
Kindly revert as soon as the codes have been added to the backend of your website so that I can check from my end and see if the codes are firing as expected..
Can you provide a screenshot of the GP Hook elements, where you added the codes ?
https://drive.google.com/file/d/1gB54kj7vFNt73SvOGyqOO79LtpazkIYs/view?usp=sharing
https://drive.google.com/file/d/1BFV0_JkQ_IXQWGDVlOIq7RuuZBAN93_g/view?usp=sharing
https://drive.google.com/file/d/1VsLmfZkOFSLTlKOeZvy46m-vdy3qeKYX/view?usp=sharing
https://drive.google.com/file/d/1rQiJel3QrE0IlELa4nYrnrBGeXs_H864/view?usp=sharing
Ah ok, in the JSFiddle links, you will see the code eg.
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-1072711480"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-1072711480');
</script>
That is what needs to be added in the Hook Element, NOT the URL to the jsfiddle.
I'm sorry, would you clarify a question?
Does the code you've given me go in both the header and footer or are there different codes for each?
Michael
Hi Michael
Try hooking the code here to wp_head: https://jsfiddle.net/4Lh7zvkn/
Whereas this one, try hooking the code to wp_body_open: https://jsfiddle.net/yfzb86gL/3/