WordPress

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.

edge

Share
Published by
edge
Tags: WordPress

Recent Posts

Disable Copilot on Windows 11 via Group Policy GPO

If using Copilot right from the Taskbar isn't your thing, you should disable it. Even…

8 months ago

Setting Default Fonts in Word, Excel, Outlook, and PowerPoint via Group Policy

In an environment where standardizing things does matter, setting default fonts in Microsoft Office apps…

9 months ago

Wake-On-LAN (WOL) with Windows and PowerShell

Wake-On-LAN is a networking standard that lets you wake up a computer from either a…

9 months ago

How To Remove Restrictions Set in A Password-Protected PDF File

First of all, this is not to bypass a PDF file that requires a password…

9 months ago

How To Move My Outlook Navigation Bar Back From Left Back To the Bottom

Microsoft has been lurking about the idea of placing the Outlook navigation bar to the…

2 years ago

Headset with Microphone Echoing My Own Voice on Windows, What To Do?

One colleague came up to me the other day asking me to take look at…

2 years ago