Get 10% OFF hosting service at AlexHost with this voucher code: L59CD15KZ9Y6

How to block visitors from some countries on WordPress

There are some use cases that it makes sense to block visitors from particular countries because you don’t target them. Or, most of the visitors from those countries are mostly spambots. Or even worse, most of them are the source of your fake traffic or the unsolicited e-mails in your inbox? Or you want your blog to be local, so only visitors from your country and some nearby countries can visit it?

Whatever the situation, here are some ways to block them to visit your WordPress blog.

Plugins

There are many  WordPress plugins for this purpose. I am not sure which of them are the best one. But I believe every blog and its owner is unique. Therefore, every one of them should do their homework to find the plugin that works best for them.

Custom functions

If you don’t want to install any plugin, you can write custom functions by yourself. It will need a database of geo locations to perform well. You can get such a database for free  here.

Cloudflare

Don’t want to install a plugin but you don’t want to meddle with your theme’s codes either? Cloudflare can be your best answer. 

With Cloudflare in front of your WordPress, you won’t need to install any plugin to block visitors from certain countries. All you need is setting up a firewall on Cloudflare dashboard. Then, you need to write the firewall rules to make it happens.

Be careful with the rules. Because setting up a wrong one will block some bots from a major search engine to visit your WordPress blog. I bet none wants this.

Make it private

Another way to block some visitors from some countries is making your WordPress blog private. To go with this way, you need to set up a huge list of visitor’s e-mail. Then, you need to import them into the WordPress subscriber list.

After that, just set the privacy of your WordPress to allow only registered visitors.

Is it worth the effort?

For me, yes. Blocking some countries to visit my blog reduces the spam comments and unsolicited e-mails by 99%. If you’re facing the same issue as mine, you may give it a try.

The easiest way is by using Cloudflare. Not only you can block them easily, but you’ll have many other advantages such DDoS protection from their system.

Verdicts

None can tell you if you need to do this. But if you do need it, or just curious to give it a try, I will recommend going with plugins way first.

However, so far, the best and accurate way to block visitors from some countries is using Cloudflare’s firewall rules.

Please keep in mind that blocking them will reduce some portions of your visitors. Not only that, but you’ll also have a risk with your SEO.

You can minimize the risk by writing the firewall rules carefully. 

In my case, it even boosts my SEO for my targeted countries. While at the same time, I see the drop in the number of visitors from the blocked countries.

At last, do it with your own risk.


Categories: WordPress  

Tags: wordpress