Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

So I have got one hater in India who bombarded on my adsense ad units. Luckily I didn't get banned from Google. I have blocked Indian visitors from my site using iq-blockcountry plugin (wordpress). Now I want to know if there's any procedure so that I can allow the Indian visitors but hide the adsense units from them? I don't want to block all visitors just because of one foolish person.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Good way to do this is - switching from AdSense to DFP Small Business. You can display AdSense with DFP and apply Geo-targeting feature.

(I do not know Sam Azgor, but that looks to me like very fine step-by-step explanation.)

That needs some time and effort and that is a good way. Now, the bad way - quick an risky: you can try some hacking in file iq-block-country.php, line 351:

if (is_array ( $badcountries ) && in_array ( $country, $badcountries )) {
    $blockmessage = get_option ( 'blockcountry_blockmessage' );
    header ( 'HTTP/1.1 403 Forbidden' );
    print "<p><strong>$blockmessage</strong></p>";
    exit ();
}

You may try this, instead:

if (is_array ( $badcountries ) && in_array ( $country, $badcountries )) {
    define('ADSENSE_HEADER', '');
    define('ADSENSE_CONTENT', '');
} else {
    define('ADSENSE_HEADER', '<script type="text/javascript"><!--google_ad... etc... </script>');
    define('ADSENSE_CONTENT', '<script type="text/javascript"><!--google_ad... etc... </script>');
}

And, in your template - just print them:

<?php echo ADSENSE_HEADER; ?>
<?php echo ADSENSE_CONTENT; ?>

Example above is also a good example of bad coding (downvoting would not be surprise here), but it is an answer, I believe.

Very important: if you go with "bad way" - prepare your backups. If something goes wrong, I can not help you. Consider that as a pseudocode, and if works - as a temporary solution, and ask "iq-blockcountry" developers to implement "AdSense feature".

share|improve this answer
    
Cool! Thanks for the code, I'll try it. –  Chankey Pathak Aug 23 '12 at 6:19

You could conditionally hide the ad block with some geolocation service. However you cannot be 100% sure that you are going to block all IPs from India.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.