[Support request] Add Adsense Auto ad code for AMP pages

Home Forums Support [Support request] Add Adsense Auto ad code for AMP pages

Home Forums Support Add Adsense Auto ad code for AMP pages

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1384243
    Gian

    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

    #1384503
    David
    Staff
    Customer Support

    Hi there,

    to add code immediately after the opening <body> tag use the wp_body_open hook

    #1384900
    Gian

    Hi David,

    I’ve changed yesterday the hook to wp_body_open https://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?

    #1384990
    Gian

    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_open and 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

    #1385058
    Tom
    Lead Developer
    Lead Developer

    To have your code appear before the closing </body> element, you’d need to use the wp_footer hook.

    Elements simply adds your content into the specified location – if you can see it in the source, it’s working.

    #1385070
    Gian

    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_footer hook 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_footer selected as you can see here https://imgur.com/a/s5BIpB6

    The 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

    #1386002
    Tom
    Lead Developer
    Lead Developer

    I 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.

    #1386008
    Gian

    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.

    #1386249
    Tom
    Lead Developer
    Lead Developer

    That’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 🙂

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