How to Block an IP address in WordPress

This post shows you how to block an IP address in WordPress. Why would you need to do this? Well, it turns out that there are many reasons! First, this post discussed blocking a specific spammer’s IP.

Recently, my WordPress blog ( got spammed daily. Of course, I expect an occasional WordPress spam comment, but thousands of spam comments in one day is quite annoying! Fortunately – the spammers were unsuccessful due to the spam filtering features implemented in WordPress. But, unfortunately, this created more traffic, used more bandwidth, consumed more space, and wasted my time.

Any good WordPress site has some sort of spam filter enabled. Akismet is a top-rated spam filter, but you could use others such as Anti-Spam by CleanTalk. There are many more anti-spam services available. A spam filter is essential if you allow comments and allow pingbacks and trackbacks.   I use Akismet since it is quite successful at blocking spam; it is also an official free plugin.

YouTube player

Blocking an IP address using WordPress

You can identify the offending IP address by looking at the comments section in WordPress.

WordPress Comments
WordPress Comments View

Below is an example of the IP address that is spamming my WordPress blog. In this case, it is, but I have noticed this IP address is one of a few ranging from –

WordPress Comment with IP Address
WordPress Comment with IP Address

For information sake, I looked up the IP address using CleanTalk’s blocklist checker, which is available at This showed me that this IP address originates from Russia, and it had a 67% spam rate.

Navigate to the WordPress settings section and add the offending IP address to the comment blocklist using the IP address from the comments section. Notice that you can add multiple IP addresses here, so I added all the IP addresses I wanted to block.

WordPress Settings Comments Blacklist
WordPress Settings Comments Blacklist

Other Methods to block IP addresses for WordPress

There are other methods to block an IP address for WordPress. Many bloggers prefer using the .htaccess file in the WordPress root folder on the Linux hosting server. The .htaccess file will not only prevent the IP address from posting comments, but rather it will stop that IP address from accessing the WordPress site completely! This is a slightly harsh approach but may be warranted if the IP address is attempting more evil acts other than spamming you.

The syntax to block an IP address using the htaccess file is this:

Order Deny,Allow
Deny from

First, you will need to copy the code into a text file and upload it to your site. The text file should be renamed to .htaccess. You can also use this handy tool to help you with the .htacess file creation:

Some hosting service providers also provide facilities to block IP addresses using hosting panels such as CPanel. See below:

The CPanel IP Blocker is great since it provides many options to block IP addresses.

You can block a specific IP address such as ‘’. The IP Blocker also allows entire IP address ranges such as ‘’

It supports both IP v4 and IP v6 addresses.

Be careful, though! These settings will affect your entire site. Use .htaccess if you wish to block specific areas f your site. As discussed, the WordPress admin interface also allows blocking, but it is limited to comments.

You may also be interested in

About the Authors

Anto's editorial team loves the cloud as much as you! Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! Contact Anto Online if you want to contribute.

Support the Cause

Support Anto Online and buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee

About Anto Online

Having started his career in 1999 as a Desktop Support Engineer, Anto soon changed paths and became a developer. After several years of development experience, he transitioned into a consultant. As an enterprise application consultant for a leading SaaS software provider, Anto specializes in AWS's serverless technologies. By day, Anto focuses on helping customers leverage the power of serverless technologies. By night, he indulges his passion for cloud computing by playing with Python and trying out things that are currently beyond the scope of his work. Sometimes Anto needs help as there are not enough hours at night. So Anto relies on a team of fellow Cloud enthusiasts to help him out. Each one is a Cloud expert in their own right, and Anto takes great pride in helping them learn and grow.

View all posts by Anto Online →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.