Pinkyui Article How to add In-Article Ads automatically in Era Material
Pinkyui https://pinky-ui.blogspot.com/2019/01/in-article-ads.html

How to add In-Article Ads automatically in Era Material

There are many ways to add In-Article Ads (AdSense) on Blogger. Even so, I have added a special way to add In-Article Ads in Era Material.

By using a Blogger tags and JavaScript you can add In-Article Ads in Era Material automatically.

Go to Blogger Dashboard > Theme > Edit HTML, Ctrl + F on your keyboard and search blogger comment code like a below:

<b:comment>Post body</b:comment>

On below the code as above you can see code like a below.

<div class='post-body' expr:id='"post-body-" + data:post.id'>
  <data:post.body/>
</div>

Example:

Post body

And replace all code above with the code below.

<b:if cond='data:view.isPage'>
<div class='post-body' expr:id='"post-body-" + data:post.id'>
  <data:post.body/>
</div>
</b:if>

<b:if cond='data:view.isPost'>
<div class='post-body' expr:id='"post-body-" + data:post.id'>
<div expr:id='"post1-" + data:post.id'/>

<div class='ada' id='Ads-Article'>
  <div class='adac'>
    Your In-Article Ads code here
  </div>
</div>

<div expr:id='"post2-" + data:post.id'>
  <data:post.body/>
</div>
<script>//<![CDATA[
(function(){/*]]>*/var post_id="<data:post.id/>";//<![CDATA[
var p1=document.getElementById('post1-'+post_id),p2=document.getElementById('post2-'+post_id);var s=p2.innerHTML,t=s.substr(0,s.length/2),r=t.lastIndexOf(' ');if(r>0){p1.innerHTML=s.substr(0,r);p2.innerHTML=s.substr(r+1)}})();//]]>
</script>
</div>
</b:if>

Replace "Your In-Article Ads code here" with your In-Article Ads code. Example like a below:

<div class='ada' id='Ads-Article'>
  <div class='adac'>
    <ins class='adsbygoogle'
     style="display:block; text-align:center;'
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client='ca-pub-xxxxxxxxxxxxxxxx'
     data-ad-slot='xxxxxxxxxx'></ins>
  </div>
</div>

Save theme.

In-Article Ads only can display on posts.

If you want to display it on pages including posts please use code below.

<b:if cond='data:view.isSingleItem'>
<div class='post-body' expr:id='"post-body-" + data:post.id'>
<div expr:id='"post1-" + data:post.id'/>

<div class='ada' id='Ads-Article'>
  <div class='adac'>
    Your In-Article Ads code here
  </div>
</div>

<div expr:id='"post2-" + data:post.id'>
  <data:post.body/>
</div>
<script>//<![CDATA[
(function(){/*]]>*/var post_id="<data:post.id/>";//<![CDATA[
var p1=document.getElementById('post1-'+post_id),p2=document.getElementById('post2-'+post_id);var s=p2.innerHTML,t=s.substr(0,s.length/2),r=t.lastIndexOf(' ');if(r>0){p1.innerHTML=s.substr(0,r);p2.innerHTML=s.substr(r+1)}})();//]]>
</script>
</div>
</b:if>

Done, if anyone wants to be asked, please comment.

Loading...

Love the post? Share it!

illvart
Posted by: illvart

Consider supporting us:

If you feel the article on this blog is useful, please consider supporting us. You can choose many options to support us by donate, including using the Bank, Crypto and others. Thanks.

Donate