How to Ban Unwanted Visitors from Accessing Your WordPress Blog


There are always some website visitors who don’t contribute anything of essence but keep posting hurtful or negative comments. In my experience, more often than not, these people don’t tend to change their behavior even when they are being asked to do so (first, politely, then in a harsher manner).

It’s best not to feed such trolls by acknowledging them at all. And if they are persistent, I advise banning them from your site altogether.

Find the Visitor’s IP Address


WordPress commenters’ IP addresses

If you want to ban someone, usually a comment troll, from accessing your blog, the first thing you need to figure out is that person’s IP address.

I have already written about finding out your own IP address in an earlier post.

To find out the troll’s IP address, go to WordPress Dashboard > Comments.

WordPress logs the name, email address, web address, and IP address of each of your commenters for you.

Now simply write down or copy the IP address you wish to ban to Notepad or Notepad++.

WP-Ban Plugin

Install the WP-Ban plugin created by Lester Chan. That’s the guy who also created the WP-PageNavi plugin I already wrote about.

To ban unwanted visitors, go to WordPress Dashboard > Settings > Ban.

Here, you can ban a single IP address by simply typing or pasting the IP address into the box next to Banned IPs and then clicking on the Save Changes button.

But you can do much more here.

You can not only ban single IP addresses, but also ranges of IP addresses, host names (e.g., referrers (sites referring visitors to your site), and user agents (spiders, robots, crawlers, etc.).

You can also show the unwanted visitors a personalized message. That’s always fun.

Simple IP Ban Plugin

Alternatively, you can use the Simple IP Ban plugin that works in a very similar fashion to WP-Ban.

As its name suggests, this is a slightly simpler plugin. Nevertheless, it does the job well.

Via WordPress Dashboard > Settings > Simple IP Ban, it can ban single IP addresses, ranges of IP addresses, and user agents. And you can redirect unwanted visitors to a specific URL address.

Simple IP Ban

Simple IP Ban

Showing Them a Specific Page

As I mentioned above, you can create a specific page and redirect all unwanted/banned visitors to that page.

There, you can either list the reasons why visitors to you site get banned or you can get creative and display something funny.

Otherwise, all banned visitors will be displayed a standard 403 — Forbidden error page, such as this:

Error 403 — Forbidden

Error 403 — Forbidden

Blocking via .htaccess

You can achieve the same things via editing your root .htaccess file on your web hosting server.


If you don’t know what a .htaccess file is, it is much more reasonable to use one of the plugins mentioned above at this point. Once you brush up on the topic of .htaccess, you can always deactivate the plugin and ban unwanted visitors using the .htaccess way.

To ban a single IP address, add the following lines to your .htaccess file:

To ban several IP addresses, use:

To ban a range of IP addresses, use:

The above example will ban all IP addresses from to

To ban a host name, use:

It is also possible to block traffic from referring sites and to ban user agents via .htaccess. But that’s a bit more complex stuff that I’ll safe for another post.

Liked this post?

Subscribe to our newsletter to receive early notification of new posts and deals:
[mc4wp_form id=”45″]

Next Post »« Previous Post