How to create an ad unit that supports AMP pages

Here is an example of placing AdSense ad units on the AMP-pages of the WordPress site:

1) Add an AMP script in the page code between the head tags that will load the required libraries:

<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>

If you use the recommended AMP plugin from Automattic, then the head tags are here /wp-content/plugins/amp/templates/html-start.php

2) Create an adaptive ad unit in your AdSense account. Let’s find in its code the identifier of the publisher (for example ca-pub-0066847942845019) and the ad unit ID (for example 1234567890).
Insert the code below into the page where you want to place the ad unit, replacing the value data-ad-client with the previously found publisher ID and data-ad-slot with the ad unit ID:

<amp-ad width="100vw" height=320
type="adsense"
data-ad-client="ca-pub-0066847942845019"
data-ad-slot="1234567890"
data-auto-format="rspv"
data-full-width>
<div overflow></div>
</amp-ad>

If you use the recommended AMP plug-in from Automattic, then the code should be inserted in /wp-content/plugins/amp/templates/single.php.

Leave a comment

Leave a Reply