AdSense and AMP in WordPress

Editor’s note

The purpose of the gist in this and other posts is to show examples of how things would work if you would like to use a given functionality in an AMP-compatible way, but don’t have a plugin providing that functionality in AMP yet. Make sure to check if there is a plugin that supports AMP for your functional or visual needs. Note also that these gists are not supported plugins, and that you should take advantage of them in the same way that you use code as you learn new technologies.

This post captures a knowledge aspect gathered from the Official AMP plugin Support forum. The community asks interesting and important questions in the forum, and the engineering team driving the development of the plugin provides equally cool answers worth spreading.

Support Question

Can you please let me know what is the proper way to add auto amp AdSense code to your plugin? I am using the Reader mode.

@manux_os

Official AMP plugin user

Background

Website monetization is the process of converting existing traffic being sent to a particular website into revenue. The most common way of monetizing websites is via advertising. And AdSense is one of the most popular advertising platforms nowadays, which allows you to monetize your site by displaying ads.

A powerful new way to place ads on your site is to use AdSense Auto ads. Auto ads use machine learning to make smart placement and monetization decisions on your behalf, saving you time. Place one piece of code just once to all of your pages, and let Google take care of the rest. Some of the benefits of Auto ads include:

  • Optimization: Using machine learning, Auto ads show ads only when they are likely to perform well and provide a good user experience.
  • Revenue opportunities: Auto ads will identify any available ad space and place new ads there, potentially increasing your revenue.
  • Easy to use: With Auto ads you only need to place the ad code on your pages once. When you’re ready to use new features and ad formats, simply turn them on and off with the flick of a switch — there’s no need to change the code again.

The Right Way

Similar to the scenario for injecting GTM functionality, the proper way to enable AdSense in your AMP WordPress site is to use a plugin which provides the capability in an AMP compatible way.

There are surely many available options for Ad Sense plugins for WordPress. Not many of them ensure AMP compatibility, but some do. A couple of examples are the Advanced Ads plugin, and the Ads for WP plugin. If you want to work with an Ads plugin which does not support AMP, we encourage you to reach out to the authors of that plugin and request the feature of AMP compatibility, and tell them to reach out to us if they have questions or need help.

An Alternative

If you can’t or don’t want to use these plugins at all, you still can follow the developer route and the plugin will provide the support you need to make sure that any markup you inject into your AMP pages is valid AMP, and that only valid AMP will be served from your site.

As a specific example, the following plugin contains code to inject AMP Auto Ads to your WordPress AMP pages:

You can use this gist code directly on your site, and you just have to replace the line defining the AD_CLIENT with the data associated with your Ad client id. See the installation instructions at the end of the gist for guidance. Thank you Weston Ruter!

Comments(5)

  1. So I must necessarily include two plugins, the official AMP and another one to display ads?

    This means more weight for the site, the AMP plugin should already bring that option by default, in which you can enter the Adsense code and it will propagate automatically,

    that would be great for a next update, for the moment I will analyze if I add the second plugin or better I disable the AMP

  2. Sir I’m very in line your Adsense Amp plug -report in wordpress functionality, but I still need more of this good technical report of yours.To be able to broaden my knowledge more on word press.
    Thanks.

    1. Currently, The AMP plugin does not provide any feature that can enable auto ads, so a third-party plugin or code snippet is required to insert ads on your site.

Leave a Reply

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