Default plugin of AMP for wp allows the only Header and above the content. But Not supports within paragraph and Sticky ad also sticky banner ad above.
How to add Adsense ad in amp version WordPress
Above the fold ad
<amp-ad
layout=”fixed-height”
height=100
type=”adsense”
data-ad-client=”ca-pub-xxxx”
data-ad-slot=”xxxxx”>
</amp-ad>
Insert Post Ads plugins
(lh-multisite-ads.php)
Below the fold
<amp-ad
layout=”responsive”
width=300
height=250
type=”adsense”
data-ad-client=”ca-pub-xxx”
data-ad-slot=”xxx”>
</amp-ad>
<amp-ad width=350 height=100
type=”adsense”
data-ad-client=”ca-pub-xxxx”
data-ad-slot=”xxx”>
</amp-ad>
<amp-ad
layout=”responsive”
width=300
height=250
type=”adsense”
data-ad-client=”ca-pub-xxxx”
data-ad-slot=”xxxx”>
</amp-ad>
- Open Plugin Editor (Not Theme Editor).
- Choose AMP plugin and Press Select Button.
- Open amp/templates/single.php file.
- Find <div class=”amp-wp-content”> line. And below the line paste our AMP Comfortable Ad code (Which described above paragraph).
- Find do_action( ‘amp_post_template_footer’, $this ); before the php starting tag paste Google AMP Ad code.
- Save the file. All Set.
Post Adverts plugin
Make home page to AMP version
works by plugin Accelerator mobile pages for WordPress.
Adding Adsense ads with AMP for wp plugin within content
After any paragraph 2& 5 or
/wp-content/plugins/accelerated-mobile-pages/templates/design-manager/design-3/elements/content.php
based on which design you are using on accelerated-mobile-pages by default its 2
// Normal Front Page Content
if ( ! $amp_custom_content_enable ) {
$ampforwp_the_content = $this->get( ‘post_amp_content’ ); // amphtml content; no kses
(replace by below)
$content = $this->get( ‘post_amp_content’ );
$contents = explode(“</p>”, $content);
$p_number = 1;
foreach($contents as $content){
echo $content;
/* Ad after 2nd paragraph */
if($p_number == ‘2’){
echo’ <center><amp-ad class=”amp-ad-1″ type=”adsense” width=300 height=100 data-ad-client=”ca-pub-xxx” data-ad-slot=”xxxx”></amp-ad></center>’; } /* Ad after 5th paragraph */ if($p_number == ‘5’){ echo ‘<p></p>’; echo'<center> <amp-ad class=”amp-ad-5″ type=”adsense” width=300 height=250 data-ad-client=”ca-pub-xxxx” data-ad-slot=”xxx”></amp-ad></center>’; }
echo ‘</p>’; $p_number++;
}
AMP Sticky Ad
Header Script:
<script async custom-element=”amp-sticky-ad” src=”https://cdn.ampproject.org/v0/amp-sticky-ad-1.0.js”></script>
Body tag
<amp-sticky-ad layout=”nodisplay”>
<amp-ad width=”320″
height=”50″
type=”adsense”
data-ad-client=”ca-pub-xxxx”
data-slot=”slot id”>
</amp-ad>
</amp-sticky-ad>
AMP Auto Ads
Only Upto 3 ads available with amp auto ads
<script async custom-element=”amp-auto-ads” src=”https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js”></script>
wp-content/plugins/accelerated-mobile-pages/includes/vendor/amp/templates/ header-bar.php
place above script in the header
Below Script In Body:
<amp-auto-ads type=”adsense” data-ad-client=”ca-pub-XXXXXX”></amp-auto-ads>
wp-content/plugins/accelerated-mobile-pages/includes/vendor/amp/templates/footer.php
How to insert Head & Body Tag in AMP Pages WordPress?
We can easily insert header and body section of the default amp plug in by Automattic. but AMP for WP Once we insert after the updating the code will vanish.
so we need to use a plugin, unfortunately, there are amp plugins not yet launched on WordPress plugin directory.
How to Find Header Php in AMp for wp Plugin
Adding code to header section
/*
* Adding Header and Footer Code in AMP pages in WordPress
*/
add_action(‘amp_post_template_header’,’awts_amp_my_custom_head’);
function awts_amp_my_custom_head($amp_template) {
?>
<script async custom-element=”amp-auto-ads” src=”https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js”></script><?php
}
//BOdy Tag
/*
* Adding Header and Footer Code in AMP pages in WordPress
*/
add_action(‘amp_post_template_footer’,’awts_amp_my_custom_footer’);
function awts_amp_my_custom_footer($amp_template) {
?>
<amp-auto-ads type=”adsense” data-ad-client=”ca-pub-XXXXXX”></amp-auto-ads><?php
}
AMP Plugin by WordPress Add header to Auto Ads & Sticky Ads
plugin >> editor>>AMP>>Templates>>header-bar.php
js files (auto ads, sticky ads.js amp ads js)
Before closing body tag
Templates>> html-end.php
<amp-sticky-ad layout=”nodisplay”>
<amp-ad width=”320″
height=”50″
type=”adsense”
data-ad-client=”ca-pub-xxxxxx”
data-slot=”slot id”>
</amp-ad>
</amp-sticky-ad>
Remove / Update ? clear AMP Google cache
Generally, Google Removes amp cache automatically within 3 days after a lot of 404 errors.But we can remove the content quickly within hours or within a day by sending an update ping request or terminal. But here is a simple way clear amp cache.
just append your URL to clear the cache
https://cdn.ampproject.org/c/s/YourURLpathwithouthttp
the above URL redirects to a NON AMP version.
Removing entire website cache may not works.
Ask a Question:
You must be logged in to post a comment.