Install & Enable AMP Auto Ads by AdSense Labs in Worpdress - How To

Come aggiungere gli annunci automatici AMP AdSense (e/o altro codice HTML AMP-only) su Wordpress

If you're a Google AdSense user you will probably know about AdSense Lab, the incubator hosting those brand-new Ad-based features that aren't yet ready to be rolled out to all AdSense publishers. The new deal these weeks is called AMP Auto Ads, a new family of advertising units that will be placed automatically within the AMP pages of our website/blog.

In the unlikely event you dont' know what an AMP page is or if you never heard about the AMP Project, we strongly suggest to fill this huge SEO & accessibility gap by taking a look at the AMP Project's official page.

The AMP Auto Ads feature is currently in beta and thus accessible only for those who are explicitly invited via e-mail from AdSense Lab. For additional info, read this official guide from Google AdSense. However, since you are here, there's an high chance you already know everything about AMP Auto Ads and you're looking for further info about how to properly implement them on your WordPress website or blog.

How to implement AMP Auto Ads

Let's start with taking a look at the two AMP Auto Ads client-side scripts that needs to be inserted into any AMP page:

Within the <HEAD> element

Immediately after the <BODY> element

This is quite different from our standard AdSense code snippets, expecially if we're used to manage our banners using some WordPress plugins such as the exceptional Ad Inserter. Unfortunately, most of these plugins won't help us because they are not meant to place something inside the <HEAD> or, even worse, immediately after the opening <BODY> tag... Not to mention the fact that these scripts needs to be excluded from any non-AMP page.

What can we do then?

How to Implement AMP Auto Ads in WordPress

Luckily enough, the AMP for WordPress plugin - which is almost mandatory if you want to enable AMP support on WordPress - includes,  among its neat set of helper functions, the
is_amp_endpoint() method, which can be used to determine if the current execution's context will serve an AMP page or not.

Thanks to this function, all we have to do is to edit our WordPress Theme's
header.php file (using Appearance > Editor) and implement the two AdSense scripts in the following way:

It goes without saying that we need to replace the
ca-pub-XXXXXXXXXXXX sample string with the actual AdSense ad-unit id code.

That's it for now... happy advertising!

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

8 Comments on “Install & Enable AMP Auto Ads by AdSense Labs in Worpdress - How To”

    1. Hello and thanks for asking: you need to copy the header.php file from the parent theme folder to the root child theme folder, so you can edit the “child copy” of that file just like the post says.

        1. You can do it manually through an FTP client or remote desktop (if you have access to the web server). That’s how I always do that.

    1. Hello there,

      I’m afraid it’s not possible with AMP Auto-Ads: the “auto” part actually means that the ad units will be placed automatically within the page (the AdSense algorithm will call the shots).

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.