Thursday, August 9, 2012

How to Encode Adsense in a BlogSpot Template

If you want to embed Adsense blocks in your theme, then you'll need to encode the Adsense javascript first. Doing so escapes the special characters and makes sure that your Adsense ads will show where you want them.

How To Encode Adsense for BlogSpot Blogs

A typical block of Adsense javascript looks like this:
<script type="text/javascript"><!--
google_ad_client = "pub-0000000000000000";
google_alternate_color = "ffffff";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="0000000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

When placing Adsense Code into your template, you need to encode some of the html characters:


  • < with &lt;
  • > with &gt;
  • " with &quot;


To do this html encoding, use http://centricle.com/tools/html-entities/ which will do it easily for you. After you get back your encoded Adsense block, you can place it anywhere in your theme file. You can make it float to the right or left so it is flush inline with any elements around it (like body text). To do this, use the following code:
<div style="float: right; margin-right: 5px;">
Insert your parsed AdSense Code from step above.
</div>

No comments:

Post a Comment