Put Google Adsense Code Inside Blogger Post
I've been asked several times how to put Google Adsense inside a single post like I'm doing with my blog. You can repeat the same ads between posts by configuring the Post widget, or add it to your sidebar using HTML widgets. It's a bit harder to place the ads inside your post because you have to put it directly to the template code. Is this post I will show you how to do this.
Converting Javascript to XML-compliant code
There is one thing you must remember first that Blogger template is very strict in XML syntax. If you make any mistake with the template code, Blogger will not accept and it may take time to correct. So, always back-up your template first and be careful while editing your template.
If you try to insert Google AdSense or any other JavaScript-based ad code to the template, Blogger may deny and return you an error message like this:
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.
If you try to insert Google AdSense or any other JavaScript-based ad code to the template, Blogger may deny and return you an error message like this:
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.
In case there's no error returned, the ads still won't show anything.
The problem is that AdSense ad code or client side javascipt code is not a valid XML, and some ASCII characters have special meaning and reserved functions to Blogger engine. It will be confused when trying to interpret your template syntax.
The solution is replacing special characters or symbols in the script to HTML code. These HTML codes will be rendered correctly when the page is generated to the viewer. Check out this list for special characters that need to be converted to HTML code:
Character Replaced with
< < > >
" "
For example, I have created a 468x60 ad unit, and Adsense give me this piece of code

The problem is that AdSense ad code or client side javascipt code is not a valid XML, and some ASCII characters have special meaning and reserved functions to Blogger engine. It will be confused when trying to interpret your template syntax.
The solution is replacing special characters or symbols in the script to HTML code. These HTML codes will be rendered correctly when the page is generated to the viewer. Check out this list for special characters that need to be converted to HTML code:
Character Replaced with
< < > >
" "
For example, I have created a 468x60 ad unit, and Adsense give me this piece of code

Using the above rule, I will convert the code into this
<script type="text/javascript"><!-- google_ad_client = "pub-1183761954518637"; /* 468x60, created 11/23/08 */ google_ad_slot = "3780780821"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
Now it's ready to put this code in your template
Put Adsense code to your template
Go to your Blogger Layout -> Edit HTML, create a backup of your template first before making any changes to your template. You can expand widget templates and edit directly from your browser, but I recommend you donwload it and edit with a HTML editor.
Now, search for this string : , this is where the body of your post will be shown. Usually, this only appear once in the template and you can find it easily.
If you want to put the ads at the top ot post, place it above this line, and if you want to put the ads at the bottom of the post, just put it under this line.
How to make it appear only to a single post?
If you have applied the "Read more" trick to only show part of the post on the front page, it's better to make the ads only show in individual posts.
Really, Blogger use the same widget code for both front page and single posts. To make something applied only to single post, you have to add some lines of code
put your ad code here....
Go to your Blogger Layout -> Edit HTML, create a backup of your template first before making any changes to your template. You can expand widget templates and edit directly from your browser, but I recommend you donwload it and edit with a HTML editor.
Now, search for this string :
If you want to put the ads at the top ot post, place it above this line, and if you want to put the ads at the bottom of the post, just put it under this line.
How to make it appear only to a single post?
If you have applied the "Read more" trick to only show part of the post on the front page, it's better to make the ads only show in individual posts.
Really, Blogger use the same widget code for both front page and single posts. To make something applied only to single post, you have to add some lines of code
This is a condition to check if the current page is front page or single post. It this is single post, anything between and will be shown.
Finally, the code for an ad at the top of post will look like this:
Finally, the code for an ad at the top of post will look like this:
referance
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2009
(20)
-
▼
January
(19)
- Meet an AdSense publisher - Matt Adams
- Generating Ad Code
- PIN Without the Pain
- Managing Ads
- AdSense for search
- Google AdSense Steps to Success
- Optimisation Essentials: Position for performance
- Optimisation Essentials: Bigger is better
- Optimisation Essentials: Dress for success
- Update on US tax forms for 2008
- Ads back up on Blogger
- Western Union payment updates
- Put Google Adsense Code Inside Blogger Post
- Light up your site
- Year in review: 2008
- Our Inside AdSense resolution
- Behind the scenes of scheduled maintenance
- Asking Dave Taylor about AdSense
- Talking AdSense optimization in Google Ad Manager
-
▼
January
(19)
0 comments:
Post a Comment