• Home
  • WordPress
  • web Hosting
    • Free hosting
    • Cheap Hosting
    • comparison cloud , vps, shared, wordpress
    • managed wordpress hosting
    • managed cloud hosting
  • page Speed
  • Deals
  • Services
  • About

RAaz Kumar .com

wordpress tutorials seo hosting etc


How to add adsense amp ads to wordpress

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>

  1. Open Plugin Editor (Not Theme Editor).
  2. Choose AMP plugin and Press Select Button.
  3. Open amp/templates/single.php file.
  4. Find <div class=”amp-wp-content”> line. And below the line paste our AMP Comfortable Ad code (Which described above paragraph).
  5. Find do_action( ‘amp_post_template_footer’, $this ); before the php starting tag paste Google AMP Ad code.
  6. 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.

 

Related topics:

  1. How to add adsense to blogger anywhere
  2. website cache best caching plugins wordpress w3tc cloudflare
  3. WordPress Adsense Plugins & Manually
  4. Adsense Optimization Improve adsense Earnings
  5. adsense on webview , adsense & admob policies & implementation

wordpress tutorials for beginners advanced complete guide to run WordPress

  • Rules to get 100/100 in Google pagespeed web core vitalsscore
  • How to add adsense amp ads to wordpress
  • wordpress password reset in 3 ways mail, phpmyadmin, mysql command
  • how i recovered hacked website site 5 times ft wordpress?
  • enable browser caching in wordpress apache nginx caching headers explained
  • W3TC w3 total cache plugin setup guide review comparison with wp rocket and wp super cache
  • Wordpress database optimization (don't neglect) plugins & phpmyadmin manually
  • Optimize css delivery inline critical css, remove unused css, render blocking css
  • Converting WordPress into static website speed after 1 second dynamic 3 seconds
  • Wordpress errors and fix
  • website cache best caching plugins wordpress w3tc cloudflare
  • Install xamp & wordpress on localhost windows
  • favicon ico Change / Add / Disable favicon in wordpress Ft Genesis Theme or any theme
  • increase wordpress memory limit (how to ) 40MB , 64 MB 128 MB or 512 MB maybe 1024MB
  • wp cron job check working or not disable enable change schedule
  • google analytics plugins for wordpress #sitekit #monsterinsights gadwp back as gainwp
  • Lazy Load Adsense to improve core web vitals - Vs revenue
  • xmlrpc php wordpress uses, disable without 403 error log message
  • wordpress change post date programmatically (auto on update like blogger
  • wordpress plugins that slow down your site and its alternatives
  • best wordpress plugins social, seo, Backup, speed up your blog
  • TOP 10 Wordpress Themes Premium/ Free & providers
  • Wordpress Adsense Plugins & Manually
  • Social share buttons for website Wordpress Blogger
  • How to bulk delete in wordpress posts, pages, Media Images, tags and categories
  • TOP 5 Best wordpress comment plugins 2020 (disable pingback, replytocom, customize form)
  • all in one seo pack vs yoast seo pressor
  • Auto post to Facebook, twitter, Google Plus Wordpress Posts 2019
  • wordpress speed optimization Speed up wordpress Score on Google pagespeed
  • How to use wordpress tags and categories
  • Wordpress duplicate thin content Issues {FIXED}
  • how to increase wordpress memory & file upload size
  • combine rss feeds wordpress
  • Reduce the impact of third-party code ,optimize JS delivery, Minify, remove unused js, pre connect, inline, lazy load etc
  • change wordpress site url
  • install wordpress on ubuntu apache nginx debian command line
  • Wordpress Security Plugins 2021 (Brute force, Login lockdown, Malware scanner etc)

 

 

wordpress Pagespeed optimization

Digitalocean free $100 Credit

Cloudways Review pricing promo codes

Siteground cpu limits Pricing

Shared Hosting

Managed wordpress Hosting

Managed Hosting Cloud server

VPS Hosting

Cloud Hosting – Unmanaged

Google cloud Pricing

Aws Pricing

Azure pricing

nginx server tutorials

apache server tutorials

linux sysadmin tutorials

mysql Commands list pdf

LEMP Install Ubuntu

Mysql Performance Tuning

Nginx Performance tuning

Linux Performance tuning

Php -fpm performance tuning

Redis Performance tuning

linux server security

nginx security best practices

wordpress security plugins

 

 

wordpress

 

Top 5  WP Google Analytics Plugins

WP Backup Plugins

Wp Comment Plugins

Top wordpress Security Plugins

WP Seo Plugins

WP Caching Plugins

Best Adsense Plugins for WordPress

Wp social Sharing Plugins

autoshare social media plugins

WP speed Optimization Plugins

Speedup WordPress google Score

More Wp tuts

Server Admin Cloud

 

Installing Nginx LEMP On ubuntu

Installing apache Lamp ubuntu

nginx fastcgi cache enable

php – fpm install  & Configuration

Opcache install & Configure

php -fpm pool manager explained

Mysql Install & Configuration

Redis Object cache install & configure

 

Nginx as Reverse Proxy and Load balancer

Load Balance / auto scaling in google cloud

Linux Commands PDF

Mysql Commands Pdf

Letsencrypt tutorial

mysqldump export & import 

Pagespeed Module install & configure

nginx.conf best file

mysql.conf best file

upgrade ubuntu

© 2023 - All Rights Reserved Disclaimer & Privacy Policy