- This topic has 8 replies, 3 voices, and was last updated 5 years, 8 months ago by
Tom.
-
AuthorPosts
-
August 1, 2020 at 1:04 pm #1384243
Gianluca
Dear Support Team,
I’ve added this code:
<amp-auto-ads type="adsense" data-ad-client="ca-pub-xxxxxxxxxxxx"> </amp-auto-ads>to display Adsense ads on the AMP version of my website.
According to the guide provided by Google https://support.google.com/adsense/answer/9261309?hl=en-GB I should add the above code immediately after the opening <body> tag.
To do so I’ve added a Hook in wp_footer > entire site https://imgur.com/a/vVVJLiq but unfortunately ads are not displaying correctly on AMP pages on mobile devices, actually they start to display after the comment section of the article, as you can see here https://imgur.com/a/gfhGklY
I’ve tried also after_header and as a location only blog post, but nothing change.
Am I missing something? Or the location for this kind of code in hooks is different?
Thank you in advance,
Gianluca
August 2, 2020 at 1:13 am #1384503David
StaffCustomer SupportHi there,
to add code immediately after the opening
<body>tag use thewp_body_openhookAugust 2, 2020 at 8:48 am #1384900Gianluca
Hi David,
I’ve changed yesterday the hook to
wp_body_openhttps://imgur.com/a/A00xCZX but still I can’t see ads on my blog, maybe I have to select execute PHP, shortcode or change priority number?August 2, 2020 at 11:10 am #1384990Gianluca
I’m trying various option to display ads, and decided to give a try to the plugin Ad Inserter https://it.wordpress.org/plugins/ad-inserter/
So, I’ve disabled the hook
wp_body_openand inserted the code<amp-auto-ads type="adsense" data-ad-client="ca-pub-xxxxxxxxxxxx"> </amp-auto-ads>here https://imgur.com/a/2kJ07vO in Ad Inserter settings, as listed on the documentation https://adinserter.pro/documentation/adsense-ads?highlight=amp%20auto%20ads#amp (paragraph AdSense code for Auto ads on AMP pages) and ads are showing up on AMP pages of my blog.
So maybe it’s an issue with hooks or something related with GeneratePress?
I would like to use hooks if possible in order to have less plugins installed.
Thank you in advance
August 2, 2020 at 1:14 pm #1385058Tom
Lead DeveloperLead DeveloperTo have your code appear before the closing
</body>element, you’d need to use thewp_footerhook.Elements simply adds your content into the specified location – if you can see it in the source, it’s working.
August 2, 2020 at 1:22 pm #1385070Gianluca
Hi Tom,
Thank you for your response.
It seems an issue with hooks in GeneratePress and AMP, because if I use AD inserter with only this code https://imgur.com/a/2kJ07vO ads shows up, while unfortunately the
wp_footerhook is not working as expected on AMP pages.If you could have a look, I’ve disabled the AD Inserter plugin and placed the code necessary to display auto Ads in Element > Hook with
wp_footerselected as you can see here https://imgur.com/a/s5BIpB6The following code:
<amp-auto-ads type="adsense" data-ad-client="ca-pub-xxxxxxxxxxxx"> </amp-auto-ads>is not showing up in the source and therefore ads are not displaying in AMP pages.
Any idea how to fix this?
Thank you
August 3, 2020 at 9:40 am #1386002Tom
Lead DeveloperLead DeveloperI am seeing the code in the footer: https://www.screencast.com/t/dj9thptWwAs
You can try increasing the priority value of the hook so it loads closer to the closing
</body>element.August 3, 2020 at 9:44 am #1386008Gianluca
Hi Tom,
I had to switch from Reader mode to Transitional mode in AMP, in order to be able to show Adsense ads in AMP pages, but I can assure you that something was causing the issue while Reader mode was activated.
August 3, 2020 at 12:47 pm #1386249Tom
Lead DeveloperLead DeveloperThat’s strange. Elements simply hook the code into the existing hooks – it doesn’t alter it in any way. It’s likely that the Ad Inserter plugin was even using the same hook (
wp_footer).Glad you got it working 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.