Skip to main content

How To Put Adsense In The Middle of Post Automatically

Many Bloggers are asking me on what code/css did I use to put ads in the middle of my posts. Well I have my post before about putting adsense ads anywhere in the posts but that is manually adding of <!-- adsense -->.  Now I will show this code that  will add the adsense ads automatically. As I research about this there are some posts about his and one is in Ajbanda article of showing ads in the middle of post, He created a code that will look for  <br/> tags on the articles, this one just simplified version of the code

How To Put Adsense In The Middle of Post Automatically

First things first: Must take backup of your template before making any change.
( Tips: Use the Asynchronous Adsense Code for Maximizing Page load)

1. Find <head> tag in your blogger template and place latest jquery just below it. Please avoid to use two jquery links, remove older one and use new version.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" ></script>

2. Second look for this code <data:post.body/> inside your template and replace it with the following code -
<div id="PostBody">
 <data:post.body/>
</div>

<div id="AdCode">
<div style='margin:5px 0;text-align:center;clear:both;'>
 <!-- Ad Unit Code Here -->
</div>
</div>

New Blogger template may have 2 or 3 <data:post.body/> code. You should have to identify correct one. Generally 2nd instance of <data:post.body/> is right code to replace in new blogger templates.
3. Now search for </body> tag inside your template and put following javascript before/ just above it.
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<script>
 $AdCode = $("#AdCode").html();
 $("#PostBody br:lt(1)").replaceWith($AdCode);
 $("#AdCode").remove();
</script>
</b:if>

4. Save the changes in Blogger template and have fun.

You can choose your Ad location

By replacing the value br:lt(1) with br:eq(n), where n= 1, 2, 3… which is number of line breaks after which Ad will appear in your post. e.g. If you want to show Ad after 5th line break then replace br:lt(1) with br:eq(5) and you are done.

Before placing the Ad codes be sure to Parse the adsense codes. You can use my parser: HERE
As I read on the adsense policy there are no specific about this one and I think this is just placing the ads inside blog post like placing it below post title which is allowed.
You can also read their Policy. Final choice is yours, you will use it for your blog or not.

Comments

  1. Thank you very much for the tutorial helped me a lot to set up my blog

    ReplyDelete
  2. Hi Again, I used br:eq(n) and it is now showing an extra ad at the end of my posts too. Can you help figure me out why this is so?

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Use Facebook, Disqus and Blogger Comment tab Together in Blogger Blogs

As writers of  blogs, we all are aware of the importance of comments. While it is true that some blogs/websites tend to disable comments entirely, those are special instances where the websites do not essentially require comments. However, in general, comments form an integral part of any blog, be it a personal one or a magazine site. After all, what good is any info unless it provokes a healthy discussion?

All blogging platforms (including WordPress) come with native support for some sort of comment mechanism which seems to suffice for most bloggers. But sometimes, users may require some dedicated or specialized comment mechanism. This is where third-party commenting systems come in handy. In this article, we will take a look at some of the major third-party commenting mechanisms

Disqus
Disqus is a mature comment management system and perhaps the most used amongst bloggers and website owners. Introduced back in 2007, it is currently serving more than 750,000 websites. According to a …

FIXED! Adsense Ads not Showing in Homepage of Blogs or Website

Problem Solved! have you experience your Adsense ads not showing on homepage? Ads are showing on other pages except for homepage, well just this week I had a hard time figuring out why my ads are not showing in homepage.

I have another blog that is using Adsense ads. After a day of fixing almost all my template errors still the Adsense ads are not showing so I tried to search for it on internet.

Some forums will tell you that it is about updating your privacy policy pages, well I did that also but there's no effect.

The solution is very simple just navigate to blogger setting or wordpress seo settings. I'm focusing on blogger since my blog is in blogger platform.




Go to Blogger settings ->> Search Preferences->> Enable search description. Click yes then put your sites description and save. That's it! reload and see the magic :D

Facebook Popup (Like Box Widget) With Time Delay

Facebook Popup Like Box Widget With Light box and Time DelayIf you are looking on how to increase your blog social media connection you can use widgets that will expose it to your reader. One of the best way is to use Facebook like box will pop up with the lightbox effect. This facebook pop up is not annoying because of its ability to detect its user cookies. It won't open when it is already closed. It has a time delay also to avoid visitors leaving your blog. Just set it in any way you want and increase your followers/likes easily.
Add Widget to Your Site Add the following code anywhere in any widget/HTML box.
Go To layout and add gadget--> HTML/JavaScritp Box Paste all the below code -> then save

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' type='text/javascript'></script>
<style>
#fanback {
display:none;
background:rgba(0,0,0,0.8);
width:100%;
height:100%;
position:fixed;
top:0;
left:0;
z-index:99999;
}
#…