-->

Type something and hit enter

Translate


On
AdSense in middle of the post – Blogger advanced practices: If you want to insert ads into your post content i.e. after certain paragraph, it is now possible on Blogger. Author “AJ Banda” created an awesome script to make it possible. This script actually looks for <br /> tags inside your post and displays ad unit. You can define a number of <br /> tag to display ad within your post content. A similar feature is already available for WordPress but Blogger is lacking for a long time but custom solution can help you.

Insert Ads into Your Post Content

Put Google Adsense in middle of post

What is additional?

1. Reduced the need for <br /> (line break) tags in his code and using CSS style “clear:both” for the same purpose.
2. Modded this code for center alignment by using HTML5 properties.
3. Add XML code which will load only on Blogger item page rather than loading on other pages to save your blog performance.

Injecting this code into Blogger theme

Now I will discuss how to install/ integrate/ inject this script into your blogger theme. (!) Must take backup of your template before making any change.
1. Find the <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 the 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 Blogger theme 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 Blogger theme 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 made in Blogger theme 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 the 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.

Legal

As far as we know using this or similar script to insert ads within your post content is legal because most of the users who are using WordPress, Joomla etc. are placing ads with the help of similar scripts. It does not matter they are using PHP or javascript. The final choice is yours, you will use it for your blog or not.
GitHub gisthttps://gist.github.com/vinayprajapati/5893386
Reference –  ajibanda.com

Conclusion

After a long research and discussion, we find that adding Google Adsense code inside post body is possible with javascript. It is absolutely safe to use it. And we recommend Blogger to introduce such feature with Blogger by default in next version which is v3.

https://www.techprevue.com/insert-ads-post-content-blogger/
Back to Top