How to Add AdSense Auto Ads to Google AMP Pages in WordPress

Posted on April 25, 2018August 2, 2018 by Matt Stephens

 

For AdSense publishers that use Google AMP by Automattic, after setting up auto ads and adding to your WordPress site, you must have noticed that Google ads don’t appear on the the Accelerated Mobile Pages (AMP) of your site.

This could cost you thousands of dollars in earnings, if a great deal of your visitors use their mobile devices.

After receiving several requests from my readers to publish a tutorial to correct this anomaly, I have decided to do just that. This tutorial will show you how to add AdSense on AMP pages.

Video Tutorial

If you don’t find the video sufficient, or you just want to know more, then continue reading.

You can easily display ads on AMP pages using several plugins. However, many of them come at an extra cost. You don’t have to spend a dime to get this done – It’s not as difficult as you imagine.

To display ads on AMP with this guide, we will be making use of the latest innovative feature called “Auto Ads”.

The auto ads feature allows you to add a simple code to your site, and after adding that code you can easily manage your ads directly from your AdSense dashboard.

Follow this guide: setup auto ads and add to WordPress

If you are very familiar with your AdSense Dashboard, you must have noticed a new feature located within Optimization>>Lab. This feature is called “AMP auto ads (text and display) – A great new way to monetize your AMP pages. Switch on this lab to place text and display ads on any AMP page that you’ve tagged with the AMP Auto ad code”.

First thing you need to do is toggle on this feature and click on get code.

You will be provided with an AMP code you have to add to two places on your website.

AdSense has a guide to add this code to your site. However, you may find this difficult to implement without proper guidance if you are not a tech savvy. This post will help you add those AMP codes to your site even if you are new to coding.

You can add AMP codes by directly customizing your AMP plugin. But the most recommended method is to add your AMP code to your theme functions.

How to add AMP codes to theme functions

Make sure you are logged in to your WordPress dashboard. Hover your mouse cursor on the appearance icon and click on editor.

Make sure the theme you want to add your AMP code to is selected and click on Theme functions (functions.php).

Recommended action: Add AMP code to a child theme and not a parent theme. Remove AMP code previously added to AMP plugin if that didn’t work.

Add the two codes below to your functions.php respectively, ensuring you replace //adsense_header_code and //adsense_footer_code with your AMP header and footers codes respectively.
//Adding Header Code in AMP pages in WordPress add_action(‘amp_post_template_head’,’nhb_amp_my_custom_head’); function nhb_amp_my_custom_head($amp_template) { ?> //adsense_header_code <?php }
//Adding Footer Code in AMP pages in WordPress add_action(‘amp_post_template_footer’,’nhb_amp_my_custom_footer’); function nhb_amp_my_custom_footer($amp_template) { ?> //adsense_footer_code <?php }
The final piece of code within your functions.php should look like the one in the image below.

With this method, Ads will begin to show up within your AMP pages. You can also verify this by visiting yoursite.com/page/amp/

If you intend to configure your AMP plugin directly (not recommended), here’s a guide for you.

 

How to add AdSense AMP code to AMP plugin

You can configure your plugin directly from your WordPress dashboard. However, it is advisable not to do that. The best way to configure your plugin is to Add the code using your FTP/SFTP client. In my case, I access my remote site using FileZilla. It is one of the best FTP clients out there.

Make sure you are logged in to your FTP client and ensure the location on the remote site points to /public_html/wp-content/plugins/amp/templates.

Under your amp>>template, you should see the filename html-start.php. right click on that file and click on edit.

Paste the AdSense header code directly below the <head> tag and the footer code directly below the opening <body tag, as shown in the image below.

 

After pasting the code in your editor, save the settings to your server.

Google Ads should start displaying in your AMP pages immediately. You can verify this by visiting any of your site/blogpost/amp in a mobile phone browser (preferably chrome browser). Google ads may not be visible in search results until around 20-30 minutes.

That’s everything about adding auto ads to your AMP pages in WordPress. Feel free to communicate your challenges if you were unable to get this done.

Subscribe to this blog using the subscription box below. Also, follow us on Facebook and Twitter to get access to our exclusive tutorials faster than anyone else.

 

Content retrieved from: https://www.naijahomebased.com/adsense-amp-code-amp-pages-wordpress/.

gareth

I am in my late 40's and originally grew up in New Zealands Bay of Islands. When I'm not reading textbooks and coding I am usually weight lifting or if lucky enjoying New Zealand beautiful outdoors. My favorite destination these days is the beautiful Queenstown

Share
Published by
gareth

Recent Posts

Transfer Learning –Deep Learning for Everyone

Posted by William Vorhies on April 17, 2018 at 12:25pm View Blog Summary: Deep Learning,…

8 years ago

Goodbye Age of Hadoop – Hello Cambrian Explosion of Deep Learning

Posted by William Vorhies on March 20, 2017 at 4:48pm View Blog Summary:  Some observations…

8 years ago

Open Source Deep Learning Frameworks and Visual Analytics

Posted by Shay Pal on January 31, 2018 at 4:16pm This was originally posted here…

8 years ago

An Executive Primer to Deep Learning

Posted by Pradeep Menon on February 20, 2018 at 4:30pm Circa 1997, the reigning world…

8 years ago

Top libraries for Distributed Deep Learning

Posted by Packt Publishing on June 13, 2018 at 12:30am The performance of the neural…

8 years ago

Python Deep Learning tutorial: Create a GRU (RNN) in TensorFlow

Posted by Capri Granville on January 27, 2018 at 7:00pm Guest blog post by Kevin…

8 years ago