How to add AMP Ads to WordPress

Looking to generate some revenue by adding AMP Ads to your WordPress theme? Follow this guide to add Google AdSense to your website.

Add Google AdSense to your AMP website

To add Google AdSense to your AMP website, follow the steps below to add them to your post singles.

Add code to header.php

  1. Open your theme’s header.php file.
  2. Add the code below to register the AMP Ads script, hosted by amp.dev in between your <head></head> tags.
  3. Wrap an if statement to pass is_singular( ‘post’ ) around the script to only use the script where Ads are to be shown appropriately.
<?php if ( is_singular( 'post' ) ) : ?>
     <script async custom-element='amp-ad' src='https://cdn.ampproject.org/v0/amp-ad-0.1.js'></script>
<?php endif; ?>

Note: please, be sure you’ve got the latest version of this required script.

Add code to single.php

  1. Open your theme’s single.php file.
  2. Copy and paste the code below, using your Ad client-ID and slot (provided by Google AdSense).
<amp-ad width="300" height="300" type="adsense" data-ad-client="ca-pub-XXXXXXXXXXXXXXXX" data-ad-slot="XXXXXXXXXX">
     <div overflow></div>
</amp-ad>