Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thegulshankumar/8b64cea909fc4b61ae8c9ddec3639318 to your computer and use it in GitHub Desktop.
Save thegulshankumar/8b64cea909fc4b61ae8c9ddec3639318 to your computer and use it in GitHub Desktop.
Block Google AdSense in Some Country
// Untested: May not work with some Cache plugin.
$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];
if ($country_code == "US") {
echo "<style>.aicp {display:none;}</style>";
}else {
echo "<script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>";
}
// Block multiple countries
<?php
$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];
$country_code = array( 'IN', 'US' );
echo "<style>.aicp {display:none;}</style>";
}else {
echo " <script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment