Site logo

Archived topic

Generic adsense code disappears from head

3 replies · Started by Javier on October 14, 2020

Viewing posts 1–4 of 4

I use a plugin to insert the adsense ads but when I insert in the head the adsense code disappears after a short time. It only happens to me in generatepress, in other themes I have no problem.
How can I create a general hook to insert the generic adsense code and not delete it automatically? Is there a way that the adsense code does not disappear from the template?

Hi there,

there isn't anything in GP that would affect the behaviour of that plugin. I would assume the plugin is adding code to core WP hooks which again GP has no awareness of or control over.

If you know where the code needs to be added you can use a Hook Element:

https://docs.generatepress.com/article/hooks-element-overview/

There are 3 main hooks for adding scripts to WP:

wp_head - inside the <head></head>
wp_body_open - immediately after the opening <body> tag
wp_footer - in the footer

For ad placement codes there is a number of Theme hooks which you can see in the visual guide:

https://docs.generatepress.com/article/hooks-visual-guide/

Thanks David,

I have created a hook in wp_head that affects the whole site, this is how the main adsense script is executed, for now it works correctly,

Javi

Glad to hear that!

This archived topic is closed to new replies.