How To Block Countries In WordPress By IP Address

How To Block Countries In WordPress By IP Address: Entire Site Or Specific Pages ?

Need a way to block certain countries from accessing your WordPress site? There are all kinds of reasons you might need to - maybe you just don't serve that country, or maybe you're experiencing issues with spam or malicious actors. No matter what your motivation, the best way to block countries in WordPress is by analyzing a user's IP address and then blocking, or allowing, them based on the location of their IP address. In this post, we'll show you how to quickly start blocking countries in WordPress by IP address using the Geo Blocker addon from Geotargeting WP.

How To Block Countries In WordPress With A Plugin

Geo Blocker gives you detailed controls for how you set up your geo-blocking. You can either block certain countries from your entire site. Or, you can just set up geo-blocking for specific pieces of content. You can also:

  • Show a message to users who are from the blocked country
  • Whitelist certain IP addresses, or exclude logged-in users from your country blocking

To get started, all you'll need is a Geotargeting WP account, and the Geo Blocker addon installed at your site. Once you have that, here's how to block countries in WordPress.

Step 1: Create A New Geo Block And Add Block Rules

To get started, go to GeoTargeting WP → Geo Blocker in your WordPress dashboard and click Add New to create a new Geo Block. Give it a name that's easy to remember (this is purely internal - no one else will see it). Then, you need to set up your Block Rules. Geo Blocker lets you configure how countries are blocked by using a series of AND/OR conditions:

  • With a set of AND conditions, all the conditions must be met in order for the block to trigger.
  • If you create another OR group, the block will trigger as long as one of the groups of conditions is met.

If you just want to block a country (or countries) from your entire site, the configuration is easy:

  • Select Country in the Block user if drop-down
  • Choose the country that you want to block from the other drop-down

If you want to block multiple countries, you can create separate Geo Blocks or use separate OR groups in a single Geo Block. For example, here's what it looks like to block two countries with a single Geo Block:

If you don't want to block your entire site, you can add other conditions using the AND button. For example, to limit your geo-blocking to your homepage, you could set up two conditions like this:

If you want to apply one rule to multiple variables you can use Global Rules. For example, if you  want to block the Front Page if the user country is either from Vietnam, Indonesia or Japan, you have to do it like this:


The list of potential conditions is quite detailed, so you have a lot of potential ways to configure your Geo Blocks. You can even target your Geo Blocks by:

  • Device
  • Referrer
  • User logged-in status
  • Lots more conditions

Step 2: Set Up Your Block Options And Publish

Once you've set up your block, scroll down to the Block Options section. Here you can:

  • Customize the message that blocked countries see (you can use HTML if desired)
  • Choose whether or not to exclude search engines and crawlers from being blocked
  • Whitelist certain IP addresses to allow them through the block even if they're in a country that is blocked

Once you've configured those options, click Publish to start blocking the targeted countries.

Other Options For Handling A Country's Traffic

If you don't want to completely block a country in WordPress, you also have some other options for how to handle the traffic from a certain country. One way is to show different content depending on where a user is from. And another way is to redirect users to a different page based on their country or location. For more information on all the addons and the possibilities that Geotargeting WP offers, you can head to the homepage.

Powered by Froala Editor