Monday, April 20, 2009

Joomla v1.5 and Google Adsense

If you have a website built using joomla (version 1.5) and want to place google adsense ads there, there are modules available. But I wanted an easier native joomla solution. So I hacked up one myself. The main problem with joomla and placing the adsense code is, joomla filters out the script or treats them as html text.

To work around this issue you need to think outside of joomla. Here is what I did.

1) Created a new module using mod_html
2) Noted down the id of the module.
3) Logged in to the backend mysql database and put the adsense code in the module I just created. This way I bypassed all the filtering.

use <joomla_database> ;

update jos_modules set content = '<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxx";

google_ad_slot = "xxxxxxxxxxx";
google_ad_width = 180;
google_ad_height = 150;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>' where id = <module_id> ;


Just remember not to edit this module again from Joomla!

No comments: