Sunday 28 June 2015

Insert Adsense in your Post Content in Blogger

 

For bloggers, an ad unit somewhere in the middle of your post can potentially boost your CTR, especially if its a lengthy post with fewer images. Unfortunately, unlike WordPress which has a number of excellent plugins for injecting ads anywhere in your blog, blogger does not have this options.


There is a simple way to solve this problem: move post body around the advertising code, just with a bunch of JavaScript and a couple of DIVs. In 2 easy steps:


Step 1:

Go to Template >> Edit Html and Find <data:post.body/> and Replace with the following Code 

<div expr:id='"aim1" + data:post.id'></div>
<div style="clear:both; margin:10px 0">
<!-- Your AdSense code here -->
</div>
<div expr:id='"aim2" + data:post.id'>
<data:post.body/>
</div>
<script type="text/javascript">
var obj0=document.getElementById("aim1<data:post.id/>");
var obj1=document.getElementById("aim2<data:post.id/>");
var s=obj1.innerHTML;
var r=s.search(/\x3C!-- adsense --\x3E/igm);
if(r>0) {obj0.innerHTML=s.substr(0,r);obj1.innerHTML=s.substr(r+16);}
</script>

Note: In the above code, replace <!-- Your adsense code here --> with your actual Adsense code.

Step 2:

Now, where ever you wan't your ad unit to appear, put a special comment:

<!-- adsense -->

We hope that this article helped you insert ads within your post content in Blogger.

No comments:
Write comments