Tuesday, January 20, 2009

Adding Adsense Code Inside Single Post Only in XML Blogger Template

A page element is applied to the general blogs layout. Adding a page element for AdSense above or below the `Blog Post` section doesn't allow you to limit the display of Google ads on a single post only. However, there is a solution to this problem.

This technique is for advance blogger but it doesn't mean the beginners couldn't do it also. Every tutorial must be understandable to beginners also, so as possible as I can, I have made simple steps to make it easy for beginners to follow. I have included useful images to make it more understandable. Lets start.

Step 1: Generate your AdSense Code

Since our concern basically is with AdSense and Blogger, we'll start by generating our AdSense code. It looks like this one.


Step 2: Cleaning your AdSense Code

Cleaning your adsense code is very important to errors. As you have observed, there are some highlighted text on the image above. These highlighted text must be remove like this image below.

Though we have already done removing the highlighted text, the code is still now clean. We still have to replace the double quotations with the single quotations. After doing it, the clean AdSense code would look like this one.


Step 3: Inserting the Adsense Code to our XML Template


To understand more clearly the thing I am going to discuss in this step, please refer always to the highlighted parts of image above.

Before you insert the code, you need to add a conditional tag to your adsense code to make it appear only on the single post. You need to insert your adsense code in between this conditional tag.

Conditional Tag:
<b:if cond='data:blog.pageType == &quot;item&quot;'>
Your AdSense Code here
</b:if>
On the `Edit HTML` section in your Layout, enable the `Expand Widget Template` to view the complete code of your template. Locate the tag "<p><data:post.body/></p>" and insert the final code above it. It should look like this image below. After inserting the code, you may now save your template.


Isn't that easy enough for beginners? If in any case there is something you don't understand or an error has appeared, feel free to comment here and I will gladly answer you the best that I could.
Related Posts Plugin for WordPress, Blogger...