There are 2 popular AMP plugins for WordPress:
- Official WordPress AMP plugin: AMP
- 3rd party AMP plugin: AMP for WP
AMP for WP should have an option for Adsense. But official one not.
I have made small inspection and noticed that all existing adsense codes are converted to amp tags – without any issues. But there is not any Ads JS file which should render these tags.
Its documentation is not good and doesn’t provide easy to fix information about this.
First i tried to add the needed JS code (for all type of ads) and tag (for auto-ads) correspondingly with wp_head and wp_footer native hookd. But no luck.
Classic mode of AMP plugin doesn’t fire any UI hook. Because it has own small template file.
So i decided to inspect the plugin’s code and to see which hooks it has for own small template.
Here is how it is seen:
So, that is it – it has own amp_post_template_head and amp_post_template_footer hooks. By using that i have solved the problem.
Here is the code:
And of course, don’t forget to enable AMP Ads in your Adsense Dashboard (via Left menu -> Auto Ads -> Auto Ads for AMP)
Discover more from WP DEV - Elvin Haci
Subscribe to get the latest posts sent to your email.