How do you go about blocking a country in WordPress so that its citizens cannot access your website? It’s possible that you got an influx of scammers, spammers, or bots from that country harassing you. Or your content just doesn’t apply to that country. Whatever the reason, we don’t judge. To achieve that, the easiest solution is to install a plugin while there are also complex methods. These methods will analyze the visitor’s IP address, and if it’s on the list, block that person from viewing certain pages or an entire site. Let’s delve into the ways to block a country in WordPress.
To Block Countries in WordPress with IP2Location Country Blocker
We’re using this WordPress plugin for demonstration purposes. Feel free to use a different one if you feel it has a feature that you need.
- Log in to the Admin Panel of your WordPress website.
- Click on Plugins in the bar on the far left.
- Choose Add New.
- Search for “IP2Location Country Blocker”.
- On the page, click on Install Now.
- You’ll be redirected to the Plugins page when the installation is complete.
- Click on Activate.
It is also possible to install a WordPress plugin via FTP. The result will be identical.
Now, depending on the license, you need to download two databases, IP2Location and IP2Proxy (Free), or IP2Location and IP2Proxy (Commercial). We recommend clicking on the IPV4 + IPV6 BIN option. You might also need to register an account on their website. Now, do this.
- Decompress the archives anywhere on your PC.
- Using the FTP details provided by the host, log in to your website via the FTP client.
- Copy the .BIN files you extracted to wp-content/uploads/ip2location.
- Your plugin now has the required database of IP addresses and can start functioning.
How to setup IP2Location Country Blocker
It’s important to mention this. This plugin will not work if you have any other cache plugins for WordPress, and you must disable them.
- Click on Country Blocker. It’s a new option that has appeared on the main menu in your Admin Panel.
- The configuration process happens in two tabs, Frontend (your website/blog) and Backend (your Admin Panel). The process is identical for both, it depends on which part you want to block access to.
- Check Enable Frontend (Backend) Blocking.
- In the first textbox, simply enter the name of the country you want to block from accessing your website.
- Unless you have advanced knowledge of WordPress, don’t enter anything in the Choose Robot.. textbox.
- Unless you have a certain proxy IP in mind, skip the next textbox too.
- Under Show the following page when a visitor is blocked. you have several options:
- Default Error 403 page. It’s pre-designed for the theme you’re using.
- Custom Error Page. If you are creative or have a fun message in mind, you can redirect blocked users to a page you created.
- URL. You can redirect users to a URL (link) of your choice. It does not have to be on your website.
- Under Blacklist the below IP addresses: you can block access to a person using a certain IP address. This is a perfect solution if someone is spamming your website, sending bots, or trying to pull off a DDoS attack.
- The Whitelist the below IP addresses: option is only useful if you intend on creating a limited-access website. You don’t have to block all countries but one, you can only allow certain IP addresses to access the website/Admin Panel.
And now you know how blocking a certain country in WordPress works. By eliminating unneeded or annoying visitors, you will save time, effort, and most importantly, your nerves.