Site logo

Archived topic

Can't Get AMP Auto Ads To Work ... HELP Please ;-)

12 replies · Started by Patrick on October 18, 2020

Viewing posts 1–13 of 13

I've added this code to Hook wp-head:

<script data-ad-client="ca-pub-XXXXXXXXXX" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script async custom-element="amp-auto-ads" src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js"></script>

... and, I've added this code to Hook wp-body-open:

<amp-auto-ads type="adsense"
        data-ad-client="ca-pub-XXXXXXXXXX">
</amp-auto-ads>

However, I still get no ads for the amp version of pages.

Here is an example:

AMP Version Of Page

Any suggestions? Thanks ;-)

Yes, it is installed and activated.

I just now placed a manual ad below the header but am still not getting any auto ads. Are you seeing just the one below the header or more than one ad per page? Thanks ;-)

Still not resolved. It appears other plugin users are having similar issues. Should I try a different hook location?

What hook location are you using?

The theme itself doesn't control this - once the necessary scripts are added in the correct location, it's 100% up to the ad provider to place them.

Hook wp-head and Hook wp-body-open for the auto ads. (not working)

Hook wp-head and Hook generate_after_header for the manual ad. (working)

Since the manual is working and auto is not, it leads me to believe that there is something wrong with the placement of the wp-body-open for the auto ads. A few other users had the same issue in the forums, but I don't want to use another plugin to make it work if I don't have to.

Yes, the plugins are working.

Using Ad Inserter, everything works fine. However, I should not have to use the additional plugin ... the issue is with GeneratePress or the GP Premium plugin. Others have had the exact same issue, not just me.

See here:

Add Adsense Auto ad code for AMP pages

Have you tried what was mentioned here?: https://generatepress.com/forums/topic/add-adsense-auto-ad-code-for-amp-pages/#post-1386008

I'm not sure how the theme could be interfering with the code - it's just HTML being added to the page. You can bypass the theme completely with some functions if you'd like:

add_action( 'wp_head', function() {
    ?>
    <script data-ad-client="ca-pub-XXXXXXXXXX" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script async custom-element="amp-auto-ads" src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js"></script>
    <?php
} );

add_action( 'wp_body_open', function() {
    ?>
    <amp-auto-ads type="adsense"
        data-ad-client="ca-pub-XXXXXXXXXX">
    </amp-auto-ads>
    <?php
} );

That takes the theme completely out of the equation.

This archived topic is closed to new replies.