AMP in WordPress: AdSense

This post is the second in a series of posts capturing knowledge gems gathered from the Official AMP plugin Support forums. The community asks interesting and important questions in the forum, and the engineering team at Google driving the development of the plugin, led by Weston Ruter, has provided 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

WP.org AMP plugin support request

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.

Leave a Reply

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