How can I hide Adsense for Wikipedia visitors?

To get the referer and see if your traffic comes from Wikipedia you can use this code:

Code:
$is_from_wikipedia = '';
if(isset($_SERVER['HTTP_REFERER'])) {
    $referar = $_SERVER['HTTP_REFERER'];
    if($referar!=''){
        $find_wikipedia = strpos($referar, 'wikipedia.org');
        if($find_wikipedia!==false){
            $is_from_wikipedia = '1';
        }
    }
}


if($is_from_wikipedia==''){
    // your adsense code goes here
}

I didn't have time to test my code but it probably works. If i am not wrong this will work only for the first page the user land on.

To be more clear i'll give you an example. The user comes form wikipedia to page_a.html having the referal wikipedia. But if he navigates to another page inside your site let's say page_b.html the referer will now become page_a.html. In this case the ads will be shown. If you do not want this PM me and i will help you with the code.

In order to put it inside your wordpress site varies depending on how you load the adsense ads (with the help of a extesion, directly in the template)
 
Back
Top