-
-
Notifications
You must be signed in to change notification settings - Fork 40
API Usage Examples
Benjamin Pick edited this page Oct 28, 2016
·
32 revisions
(Feel free to add your own.)
$userInfo = geoip_detect2_get_info_from_current_ip();
if ($userInfo->country->isoCode == 'de')
echo 'Hallo! Schön dass Sie hier sind!';
Hide/Show text only if visitor from Germany:
In your CSS file:
.geoip { display: none !important; }
.geoip-country-UK .geoip-show-UK { display: block !important; }
.geoip-country-DE .geoip-show-DE { display: block !important; }
.geoip-hide { display: block !important; }
.geoip-country-UK .geoip-hide-UK { display: none !important; }
.geoip-country-DE .geoip-hide-DE { display: none !important; }
In your HTML (e.g. in the post content, when switching the editor to the HTML mode):
<div class="geoip geoip-show-DE">
This text is shown only in Germany
</div>
<div class="geoip-hide geoip-hide-DE">
This text is hidden only in Germany
</div>
You need to enable the option Add a country-specific CSS class to the <body>-Tag
to make this work.
[geoip_detect2 property="country"] -> Germany [geoip_detect2 property="country" lang="de"] -> Deutschland [geoip_detect2 property="country.isoCode"] -> de [geoip_detect2 property="city"] -> Frankfurt/Main [geoip_detect2 property="mostSpecificSubdivision"] -> Hesse [geoip_detect2 property="mostSpecificSubdivision.isoCode"] -> HE [geoip_detect2 property="location.longitude"] -> 9.202 [geoip_detect2 property="location.latitude"] -> 48.9296 [geoip_detect2 property="location.timeZone"] -> Europe/Berlin [geoip_detect2 property="continent"] -> Europe [geoip_detect2 property="continent.code"] -> EU [geoip_detect2 property="invalid_or_empty_property_name" default="default value"] -> default value
Add the city name to the hash of the URL
add_action('wp_head', 'geoip_add_city_to_hash', 5);
function geoip_add_city_to_hash(){
$userInfo = geoip_detect2_get_info_from_current_ip();
$city = $userInfo->city->name;
if ($city) {
?>
<script>
window.location.hash = <?php echo json_encode('#' . $city) ?>;
</script>
<?php
}
}
Content of this documentation is available under Creative Commons Attribution-Share Alike 3.0 Unported License. Feel free to improve it by logging in with a Github user and editing it.