I put AdSense ads on my Wordpress plugin pages since the donation button wasn exactly raking in the dough. I inserted my AdSense code straight into these pages content. Looking through some of my stats I noticed a few of my posts got lots of hits from Google Search that would be good for ads. I didn want to show ads to my friends and normal readers so I went looking for a simple solution.
I borrowed some of the code used in this post, http://www.scratch99.com/2008/01/shylock-adsense-plugin-hack-to-avoid-adsense-smart-pricing/. One template function checks the referrer, if it returns true then you display your AdSense code in your post template, single.php in my case. This goes in your functions.php:
function scratch99_fromasearchengine(){
$ref = $_SERVER[HTTP_REFERER];
$SE = array(/search?, images.google., web.info.com, isearch., wouldel.icio.us/search, isoso.com, /search/, .yahoo.);
foreach ($SE as $source) {
if (strpos($ref,$source)!==false) return true;
}
return false;
}
and this goes in your post template where you want the ads to be displayed:
<?php if (function_exists( iscratch99_fromasearchengine)) {
if (scratch99_fromasearchengine()) { ?>
INSERT YOUR ADSENSE CODE HERE
<?php } } ?>
Related Stuff
Google Buzz Button Wordpress Plugin ReleasedIf you are looking for a Google Buzz button to add into your Wordpress site then we have released the first Wordpress plugin exclusively ...
Plug And Play Ecommerce With Wordpress PluginsSince 2003 Wordpress has slowly been gaining popularity amongst the elite of the internet, the bloggers. It is one of those few things ...
Add Google Search to Your WordPress BlogThe native WordPress search does not return very relevant results, thus it makes a lot of sense to add Google Search into your WordPress ...
Add More Sidebars to Your WordPress ThemeYou can add more than one sidebar section to your WordPress site. For example, with the stc-intermountain.org site, I added a whole bunch ...
Series Posting in WordpressIn my functions.php file, I have some code which implements series posting. This relies on the thematic ...

Original Source: