Sometimes, you may want to block traffic to your website from a particular country or redirect a user belonging to a specific country to another page of your website. In this case, you can use one of the following WordPress plugins:
IP2Location Redirection
IP2R requires the PHP bcmath
extension. When you install the extension using commands such as apt-get install php-bcmath
, yum install php-bcmath
, etc, reload PHP so that the plugin can detect the extension. In addition to the bcmath
extension, you must also enter the IP2Location Lite DB download token. To get the token, you must register an account on this plugin’s official website. Once IP2R validates the token, it will download the database, and then you can start using it.
IP2LR can redirect first-time visitors to your website to a page of your choice. It enables you to create multiple redirection conditions. For example, you can direct the traffic from China to a page with Chinese content and visitors from India to a page with Hindi content.
IP2LR detects the pages of your site and shows them in a dropdown list. It also enables you to select a country with a dropdown list. IP2Location supports WPML language codes. When you choose/enter the language code, it will translate the content automatically. IP2R lets users add the noredirect=true
URL parameter to the links. When this parameter is present at the end of the URL, it won’t redirect the URL.
You can configure IP2Location Redirection not to redirect links accessed by bots. The plugin allows you to specify multiple countries in 1 redirect condition. It also has an IP lookup tool that accepts an IP address as input and shows the IP’s country as output.
IP2Location Country Blocker
IP2LCB has been built by the developer of the above plugin, and its setup steps are similar to that of the above WP extension. It can block access to the admin area or the front end. The options for blocking the front end/back end are the same.
IP2LCB can block all countries except the ones you specify. It can block proxy IPs and allow specific bots to access the backend/frontend pages. It lets users whitelist/blacklist IP addresses and can ignore the IPs of logged-in users. IP2LCB features a statistics page where you can see the number of blocked/allowed requests to access the frontend/backend pages.
IP GEO Block
IPGB supports GeoLite2, IP2Location, ipinfo, IP-API databases and includes several options. It can block comments from visitors belonging to certain countries or requests to access the XML-RPC, wp-login page, wp-admin/themes/plugins page of the website.
IP GEO Block can block strangely behaving bots and allow uploading files of certain mime types only. It lets you create an emergency login URL and can anonymize IP addresses. You can configure it not to send the IP addresses to external Geolocation APIs and cache the IP address for a specific duration.
IP GEO Block shows a graph of the blocked requests on its statistics page. The page shows the IPs in its cache. In addition to the statistics page, you’ll also find a “logs” page in IP Geo Block. IPGP shows the activity of the extension in the logs section. You’re allowed to find records in the log by their content.
Cloudflare
Cloudflare, one of the leading CDN service providers and CDN plugins, provides a free firewall utility. The firewall of Cloudflare is preconfigured by default. You can also add five free firewall rules, including a rule to prevent visitors of a particular country from accessing your website. It is easy to create a firewall rule in Cloudflare. To add a rule, click the “Firewall rules” option that appears when you click on the “Firewall” menu after logging in to the CF dashboard and filling out the form that CF shows. The form has the following fields:
- Rule name, field, operator.
- Value, action.
Select the country from the “rule name” dropdown list and choose the operator “equals”. Now, set the value to the country whose traffic you want to block and set the action as “block”.
GeoTargeting Lite
GeoTargeting Lite can show content on your website only to visitors belonging to countries of your choice. It doesn’t have any settings. You must enclose the content in the shortcode [geot country="xxxx"]
and [/geot]
where xxxx is the country name.
GeoTargeting Lite supports CDN services such as Sucuri, Akamai, Cloudflare, etc, and is easy to use. Its premium edition supports the features you will find in the free edition of the first plugin on our list i.e. IP2Location Redirection. According to its developer, the free version of GTL may not work great with WP caching extensions.
Geolocation IP Detection
Geolocation IP detection is an excellent alternative to Geotargeting Lite. It supports integration with popular extensions such as Contact Form 7, WP Super Cache, W3 Total Cache, etc. If you’re using WP caching plugin on your website, you must activate the Ajax mode. GIPD lets users select one of the following data sources:
- HostIp Info, Maxmind City, or country database.
- Maxmind GeoIP Lite city/Precision Web-API.
- CDN service providers.
- Ipstack Web-API.
GIPD can add a country-specific CSS class to the HTML body tag. Like Geotargeting Lite, it can reveal content only to users located in countries of your choice. You must put the content between the shortcodes [geoip_detect2_show_if country="xx,xxx" not_city="xyz"]
and [/geoip_detect2_show_if]
to use this feature. xx, xxx can be the country names in the shortcode, and xyz can be a city name.
So, these are the best geolocation WordPress plugins you can use.