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.

2 Answers 2


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".


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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