How To Set Up Country-based IP Block on WordPress

If the amount of spam you get is out of control from your WordPress-based website, blocking access based on the country might be a way to try next, on top of the regular ReCaptcha method.

IP2Location Country Blocker is a free WordPress plugin that lets you block unwanted traffic from accessing not only frontend pages but backend dashboards as well by countries or proxy servers.

Before we get excited, there are one catch and two hurdles that we need to overcome.

The catch is if your WordPress-based website has cache enabled, the blocking won’t be so effective. Most likely, it will fail.

The plugin requires the PHP bcmath extension installed. If not, you will have to find a way to make it happen. Otherwise, the plugins will not work. If you are hosting your website on a VPS that you have full control of, run the commands like below to have it installed.

sudo apt update
sudo apt install php-bcmath
sudo service apache2 restart

Once you have the plugin installed and activated, you will also need to get a download token from the IP2Location Lite database. You can simply follow the instruction to get it done.

The setup is fairly straightforward, just set up countries you want to block in both Frontend and Backend sections.

And the result is very effective too. You can have a rough idea of how much access from these countries has been blocked from the Statistics page.

Leave a Reply

Your email address will not be published. Required fields are marked *