Created
April 27, 2018 06:43
-
-
Save thegulshankumar/8b64cea909fc4b61ae8c9ddec3639318 to your computer and use it in GitHub Desktop.
Block Google AdSense in Some Country
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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