Display adsense to search engines visitors only

November 19, 2008 · Print This Article

It’s a fact: People who click on your ads are people comming from search engines, not regular readers.

In order to avoid being “Smart Priced” by Google Adsense, you should definitely display ads to search engines visitors only.

Here’s how to do it.

First, we have to create a function. paste the code below in your theme functions.php file.

Create that file if it doesn’t exists.

function fromasearchengine(){
$ref = $_SERVER['HTTP_REFERER'];
$SE = array('/search?', 'images.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.');
foreach ($SE as $source) {
if (strpos($ref,$source)!==false) return true;
}
return false;
}

The $SE array is where you specify search engines. You can easily ad new search engines by adding new elements to the array.

Then, paste the following code anywhere on your template where you want your adsense ads to appear. They’ll be displayed only to visitors comming from search engines results.

if (function_exists('fromasearchengine')) {
if (fromasearchengine()) {
INSERT YOUR CODE HERE
}
}


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.