Have you ever tried to insert javascript ad code directly into your Blogger Template and it just wouldn’t work? Ok, everyone in the room can put their hands down now. This has always been a huge problem for blog authors using Google Blogger looking to monetize their site since almost all ad code contains javascript.
So why is this so darn difficult to do? The problem in the past was that Blogger users wanted more control over where and how frequently their block of ad code (usually AdSense) appeared. The Blogger Team listened to their customers and created an easy to use feature that allows you to setup AdSense in your individual posts with a simple checkbox selection.
That’s great for most people but the places where you can insert widgets are rather limited and not as flexible as you’d like. So what if you want to put AdSense, AdBrite, Chitika or any other sort of javascript-related code elsewhere on your blog without having to use a widget? The answer in the past would be, “It’s just not easy”.
You would paste the Google AdSense, AdBrite, Chitika or any other javascript ad code into your xml Blogger template only do get an error like:
“Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly. XML error message: The processing instruction target matching “[xX][mM][lL]” is not allowed.”
or another really cryptic error message like:
“Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly. XML error message: The content of elements must consist of well-formed character data or markup.“.
In fact, more recently the Blogger xml parser seems to allow javascript code in your template without displaying an error message at all. You think all is well only to discover when you view your blog that nothing actually gets displayed. Grrr.
So how can I get around this and easily use ad code or any javascript inside my xml Blogger template? Introducing, the Blogger Ad Code Converter by eBlog Templates. This simple tool will take any block of javascript or html code and replace the characters that Google Blogger ignores with the correct ones. Here’s a real life example. Say I want to put a Google AdSense 468 x 60 banner ad into the header of my blog but there’s no widget to use. You’d have to manually go into AdSense and create a new ad unit to get the code. Here’s the result:
<script type="text/javascript"><!--
google_ad_client = "pub-6044026340890176";
/* 468x60, created 3/17/08 */
google_ad_slot = "3105157606";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Now if you just pasted that ad unit code directly into your Blogger header you’d get an error or it just wouldn’t work. Most people would think Blogger was broken or wonder if it’s something they did when in fact it’s neither. The new Blogger uses xml which is much more strict and requires certain reserved characters like > < or & to be converted into xhtml entities. Here’s what your ad code needs to look like in order to work properly:
<script type="text/javascript"><!--
google_ad_client = "pub-6044026340890176";
/* 468x60, created 3/17/08 */
google_ad_slot = "3105157606";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
This only took me a few seconds to convert since I used the free and easy Blogger Ad Code Converter. There are actually posts out there that explain how to do this manually but who wants to take the time searching and replacing each character when you can convert unlimited sized ad code blocks with only one click?
After you’ve converted your ad code, paste it into your template and it should now work. Obviously before you make any changes to your Blogger template, it’s a good idea to back it up. You never know when you might make a mistake or revert to a previous version. Once you’ve done that, give the Blogger Ad Code Converter a try for free!
Actually this tool is quite powerful and can be used for encoding any HTML or javascript into XHTML entities. Some popular javascript ad codes that are converted are AdSense, Text Link Ads, AdBrite, LinkWorth, Chitika, Amazon, and more. Another good use is if you need to post a large block of HTML or javascript code into your blog post you can just use this tool.
Technically, it does so by replacing the reserved HTML characters with their XHTML equivalents. It’s basically a simple HTML Encoder that automatically replaces all HTML special characters like <, >, & into entities <, >, &.
Please note: If you are using this tool to convert Google AdSense code you don’t need to worry about breaking the AdSense program policies. This tools is just encoding reserved HTML characters into usable XHTML entities for xml Blogger. When you paste the code into your blog, save it, and then view the source code for the page, you’ll notice your AdSense code is displaying as it was originally written. This modification will not alter the functionality of the code at all, and ensures that it will be displayed within Blogger correctly.
If you like this post then please consider subscribing to our eBlog Templates RSS feed. You can also subscribe by email and have new templates and articles sent directly to your inbox.
ad code,adsense code error,blogger ad code,chitika,google adsense,html encoder,javascript,xml blogger
10 Responses to “How to Embed Ad Code Anywhere in Your Blogger Template”
2:09 am on March 19th, 2008 (subscribed to comments)
wow… interesting article
I must try to apply to my blogs..
thank for useful article
1:34 am on March 21st, 2008 (subscribed to comments)
thanks for useful article and information
how to post ads middle of the article?
1:47 am on March 21st, 2008 (subscribed to comments)
Damn good info.It was very helpful.
2:20 am on March 21st, 2008 (subscribed to comments)
That’s a good idea but I don’t think you can. Did you try pasting the ad code directly into your blog post? You’ll need to paste it in using the html editor.
9:45 am on April 1st, 2008 (subscribed to comments)
Excelent
The subjects of this blog are of great quality
Paulo Araujo
rio de janeiro - Brazil
3:48 pm on April 10th, 2008 (subscribed to comments)
One of the most informative blogger tutorials I’ve come across so far. Thank you.
4:20 pm on April 10th, 2008 (subscribed to comments)
Definitely not working for me either…
6:51 pm on April 10th, 2008 (subscribed to comments)
@jim, what is not working for you? What error message do you get?
12:29 am on April 21st, 2008 (subscribed to comments)
same here, no results when i click convert ad code i tried it 20 times already!

please fix this i really really need this are any other websites offering the same
10:04 pm on April 25th, 2008 (subscribed to comments)
i have put to my blog at http://siputurbo.blogspot.com it seem not really happen and i`m still why…because i`m use adbrite adv,when i`m convert code and then paste it….it have display but have a word written google adsense,actually i`m use adbrite…you can see in my blog at that add….anyone can help me??or this normal??
Leave a Comment