GeoIP Detection

Description

Provides geographic information detected by an IP adress. This can be used in themes or other plugins,
as a shortcode, or via CSS body classes. The city & country names are translated in different languages (supported languages).

Features:

  • Provides these 5 functions (see API Documentation):
    • geoip_detect2_get_info_from_ip($ip, $locales = array('en'), $options = array()): Lookup Geo-Information of the specified IP
    • geoip_detect2_get_info_from_current_ip($locales = array('en'), $options = array()): Lookup Geo-Information of the current website user
    • geoip_detect2_get_current_source_description(...): Return a human-readable label of the currently chosen source.
    • geoip_detect2_get_external_ip_adress(): Fetch the internet adress of the webserver
    • geoip_detect2_get_client_ip(): Get client IP (even if it is behind a reverse proxy)
  • You can use one of these data sources (see comparison):
  • For the property names, see the results of a specific IP in the wordpress backend (under Tools > GeoIP Detection).
  • You can include these properties into your posts and pages by using the shortcode [geoip_detect2 property="country.name" default="(country could not be detected)" lang="en"] (where ‘country.name’ can be one of the other property names as well, and ‘default’ and ‘lang’ are optional).
  • You can show or hide content by using a shortcode [geoip_detect2_show_if country="FR, DE" not_city="Berlin"]TEXT[/geoip_detect2_show_if]. See API Documentation.
  • When enabled on the options page, it adds CSS classes to the body tag such as geoip-province-HE, geoip-country-DE and geoip-continent-EU.
  • When enabled on the options page, the client IP respects a reverse proxy of the server.
  • If you are using Contact Form 7, you can use these shortcodes:
    • A select input with all countries, the detected country being selected by default [geoip_detect2_countries mycountry]
    • Tracking information for the email text [geoip_detect2_user_info]

See API Documentation for more info.

How can I use these functions?

  • You could choose the currency of the store based on the country name
  • You could suggest an timezone to use when displaying dates
  • You could show the store nearest to your customer
  • You show or hide content specific to a geographic target group
  • Etc. … You tell me! I’m rather curious what you’ll do with this plugin!

System Requirements: You will need at least PHP 5.4.

This extension is “charity-ware”. If you are happy with it, please leave a tip for the benefit of this charity. (See FAQ for more infos.)

This product can provide GeoLite2 data created by MaxMind, available from http://www.maxmind.com.

Troubleshooting

Does geoip_detect2_get_info_from_current_ip() return the same country, regardless of where you are visiting the site from? Maybe your server has a reverse proxy configured. You can check this: Go to the options page and look for “reverse proxy”. Are there 2 IPs listed there? If so, which one corresponds to your public IP?

Screenshots

  • Lookup page (under Tools > GeoIP Lookup)
  • Options page (under Preferences > GeoIP Detection)

Installation

  • Install the plugin
  • Go to the plugin’s option page and choose a data source.
  • Test it by clicking on “Lookup” on the lookup page.

Reviews

Outstanding Plugin

Works perfectly! However, I do wish the documentation were complete on all the variables available. It was a pain to review MaxMind, then try variations of the variable (ie. metro_code, metrocode, metroCode) until it worked.

So many uses!

I wanted to set up a redirect based on geolocation, and was able to use the shortcode version in a simple <script> to check if the user’s location matched a list I had created. While the php side of this plugin is great, the ability to access it all through shortcodes really adds a ton of power.
Love it!

Very easy to use

Took me less than 2 hours to install and configure the plugin and modify my blog pages to display or hide divs based on visitor’s country. Love it!

Read all 32 reviews

Contributors & Developers

“GeoIP Detection” is open source software. The following people have contributed to this plugin.

Contributors

“GeoIP Detection” has been translated into 1 locale. Thank you to the translators for their contributions.

Translate “GeoIP Detection” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

2.9.0

  • Add default Privacy text for GDPR compliance.
  • The reverse proxy logic was heavily changed. If you run into configuration errors, try the debug panel (see link after the reverse proxy option).
  • NEW: Reverse proxies can now be whitelisted – all non-whitelisted proxies are treated as user IP.
  • NEW: Shortcode to show/hide content dynamically. ([geoip_detect2_show_if country="US" not_state="Texas"]TEXT[/geoip_detect2_show_if]) (Thanks to @DynAggelos!)
  • NEW: All shortcodes now support multiple subdivisions ([geoip_detect2 property="subdivisions.0.isoCode"])
  • NEW: The CSS classes that are added to the body-tag (if enabled in the options) now also include the most specific subdivision (geoip-province-HE).
  • Maxmind vendor code was updated to the current version (2.9.0).

Older changelog