Archived topic
Can't Get AMP Auto Ads To Work ... HELP Please ;-)
12 replies · Started by Patrick on October 18, 2020
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:
Any suggestions? Thanks ;-)
Hi there,
Can you first confirm that you are using the AMP for GP plugin?
https://github.com/tomusborne/amp-for-generatepress
It should work with the official AMP plugin:
https://en-ca.wordpress.org/plugins/amp/
Let me know :)
Yes, it is installed and activated.
Hi there,
I'm seeing ads on that page: https://www.screencast.com/t/L6cYBY46P
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 ;-)
Hi,
Are you seeing just the one below the header or more than one ad per page?
I'm only seeing this. https://share.getcloudapp.com/E0urjWKA
Yes. Just the one below the header.
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.
wp_body_open should be placed directly inside the <body> element, which it is here: https://github.com/tomusborne/generatepress/blob/3.0.2/header.php#L27
Do any of the plugins work?
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:
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.