The GeoText plugin for WordPress allows you to display different content to your users depending on the country (or group of countries e.g. EU) they come from. Some example uses:
- Displaying different affiliate links to people depending on what part of the world they come from
- Preventing people from certain countries from viewing certain content due to legal restrictions
- Adding legal disclaimers or VAT notices that will only show for people in relevant countries
- Displaying fixed prices in different currencies that you’ve manually converted
- Linking to the user’s country specific version of a site, e.g. wikipedia
To enable this functionality, the plugin provides two shortcodes – [geoText] and [geoContent]. Both shortcodes can be inserted to pages / posts using buttons in the text editor or tinyMCE editor.
The [geoText] shortcode is designed for displaying alternate pieces of text to visitors depending on what country or group of countries they come from. For example:
You are in [geoText us="the United States" eu="Europe"]the world[/geoText]
You are in the United States to a visitor from the US,
You are in Europe to a visitor from an EU member country, or
You are in the world to anyone else.
The [geoContent] shortcode is designed for displaying larger blocks of content, including HTML, to only visitors from the specified countries or groupings. It is also useful when you have multiple countries without a grouping that you want to display the same content for. But it’s not as useful as [geoText] for just plain text. To replicate the previous example using [geoContent], it would look like this:
You are in [geoContent countries="us"]the United States[/geoContent][geoContent groupings="eu"]Europe[/geoContent][geoContent excludegroupings="eu" excludecountries="us"]the world[/geoContent]
Both shortcodes can be inserted using the buttons in the editor, meaning you don’t have to type out the shortcodes or remember the two digit country codes.
Inserting a geoText shortcode
Inserting a geoContent shortcode
However, it is worth understanding the format used for both types of shortcode.
[geoText countryCodeOrGroupingName="content to show for this country or grouping"]Default content to show if none of the shortcode parameters match the user's country[/geoText]
[geoContent countries="comma separated list of country codes that should be shown this content" groupings="comma separated list of groupings that should be shown this content" excludeCountries="comma separated list of country codes that should not be shown this content" excludeGroupings="comma separated list of groupings that should not be shown this content"]Content to be shown[/geoContent]
excludeCountries when used without the other attributes can be used to display content only to users that don’t match the excluded groupings / countries. For example, to display some content to everyone apart from those in the EU, you can use:
[geoContent excludeGroupings="eu"]This content is not for people in the EU[/geoContent]
A similar trick can be achieved with [geoText] by using an empty value:
[geoText eu=""]This content is not for people in the EU[/geoText]
Groupings are a method that allows you to easily target multiple countries without having to type (or choose) a long list of countries. The plugin comes with two groupings covering countries that are members of the European Union (grouping
eu) and countries that use the Euro as their currency (grouping
There are two ways to add groupings (or alter existing groupings) – via the plugin settings page, or by editing a spreadsheet before first activating the plugin. When first activated, the plugin gets the list of groupings from the file countries_groupings_map.csv, which is in the plugin folder. You can edit this file in a text editor or spreadsheet software to add more groupings of your choice. Please note that all country codes must be in lowercase for them to work. The plugin only reads this spreadsheet on the initial activation, so if you want to add groupings by this method, you must do this before activating it.
Alternatively, you can add and alter groupings via the plugin settings page. You can manually type a list of comma separated country codes that each grouping should contain. Or you can use the drop-down list of country names to add the country codes that way. With the drop down list, each time you change the selected option, then it will add the newly selected country’s countrycode to the list of country codes for that grouping.
Geo Text plugin settings screen
Please note that on a multisite installation, the groupings are shared between all sites. So if one site admin deletes or adds a grouping, that grouping will be deleted / added for all other sites as well. If this is a problem for you, please let me know.
The plugin looks up a visitor’s country based on their IP address, however the plugin does not include this functionality itself. Instead it supports a number of external methods to do this (in order of preference):
- Web server with GeoIP extension installed
- PHP GeoIP extension
- WordPress GeoIP Detection plugin
- ip2nation table
If your WordPress installation does not currently have Geo IP lookup ability, I would recommend installing the WordPress GeoIP Detection plugin.
While the plugin will work with the ip2nation table, it is not recommended as some of the codes provided by the table do not appear to be correct ISO 3166 country codes.
If you’d like the plugin to use the Geo IP lookup provided by some other plugin or method not listed above, please contact me and I’ll see if I can add it.
- Unzip and upload the
xoogu-geotextfolder to the
Click on the ‘Add New’ button at the top of the plugins management page in the wordpress admin area. On the next page click the ‘Upload plugin’ button. On the next page browse for the plugin zip file, then press the ‘Install Now’ button.
- Activate the plugin through the ‘Plugins’ menu in WordPress
- (Optional) In the WordPress admin dashboard, find
Xoogu GeoTextin the
Settingsmenu to configure the plugin. You should check that the Geo IP detection method is set and working. If not, then install a GeoIP detection plugin. Note that if you are using multisite and network activate the plugin, then the plugin settings are only available from the network admin panel, not from the admin panels of the individual blogs.