Google Adsense code (javascript) in wordpress pages / posts

For ages I could not work out why google ad’s included within a wordpress page didn’t work (in fact this applies to a post too). When google support pointed out that there was <br/> ‘s in my code the penny finally dropped.

So here’s the deal, I pasted the following code into my page: (In the wordpress dashboard)

firefox ad
<!– FireFox Referral –>
<script type=”text/javascript”>
<!–
google_ad_client = “pub-6732086233580907″;
google_ad_width = 180;google_ad_height = 60;
google_ad_format = “180x60_as_rimg”;
google_cpa_choice = “CAAQyaj8zwEaCIwcWMzeycafKMu293M”;
//–>
</script>
<script type=”text/javascript” src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”></script>

adsense ad
<!– Adsense Referral–>
<script type=”text/javascript”>
<!–
google_ad_client = “pub-6732086233580907″;
google_ad_width = 180;
google_ad_height = 60;
google_ad_format = “180x60_as_rimg”;
google_cpa_choice = “CAAQ__qy0gEaCP_s0gMhUOtXKL3D93M”;
//–>
</script>
<script type=”text/javascript” src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”></script>

and look what happens…..
firefox ad


adsense ad


WordPress adds page formatting to the java script that is posted, so if you look at the source, what you actually get is…

<!– FireFox Referal –><br />
<script type=”text/javascript”><br />
<!– <br />
google_ad_client = “pub-6732086233580907″;<br />
google_ad_width = 180;google_ad_height = 60;<br />
google_ad_format = “180x60_as_rimg”;<br />
google_cpa_choice = “CAAQyaj8zwEaCIwcWMzeycafKMu293M”; <br />
//–><br />
</script><br />
<script type=”text/javascript” src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”></script><br />

… DOH !!!!!!

rgds,

Nick


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>