Redirect by Country GeoIP Plugin

A few months ago I created an extremely basic WordPress plugin that allows users to redirect users based on location. You can find the code to the plugin on Github here. Simply add the PHP file in the repository to the wp-content/plugins directory of your WordPress site and the plugin will automatically activate.

The example code of the plugin sets redirect rules for users in Brazil, United States and the rest of the world. In order to properly use the plugin, you must modify the code to the proper ISO 3166 country codes accepted by MaxMind’s GeoIP configuration WP Engine’s is based on. Additionally, the destination URLs for the redirects must also be set directly in the PHP file itself.

This is only a basic example plugin to easily set redirects. In order to correctly use this plugin you must have a Business Plan or higher at WP Engine and have the WP Engine GeoIP plugin enabled. The plugin can be used to redirect based on ISO 3166 Region (State) codes as well, but it would require changing HTTP_GEOIP_COUNTRY_CODE to HTTP_GEOIP_REGION.

One Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.