WordPress is the most popular Content Management System (CMS) in the world, powering over 40% of websites. While it doesn’t have built-in IP blocking, WordPress users can do this with security plugins like Wordfence or iThemes Security. These plugins are a no-code solution for beginners to secure their site.
Blocking IP Addresses on WordPress
WordPress doesn’t have built-in tools to block IP addresses but you can do it with plugins or by editing server files. Let’s look at both options.
Blocking IPs Without Plugins
1. Using .htaccess
If your WordPress site is hosted on an Apache server, .htaccess can block specific IPs. Add the following code to your .htaccess file to block access to the login page:
<Files wp-login.php>
Deny from 192.168.1.1
</Files>
Replace 192.168.1.1 with the IP you want to block. This will prevent malicious users or bots from accessing your login page.
2. Editing PHP Files
Advanced users can also block IPs using PHP by modifying the functions.php file in your theme. Add this snippet to block specific IPs:
$blocked_ips = array(‘192.168.1.1’, ‘203.0.113.0’); // Add IPs to block
if (in_array($_SERVER[‘REMOTE_ADDR’], $blocked_ips)) {
wp_die(‘Access Denied’); }
Blocking IPs Using Plugins
If you don’t want to edit code, WordPress plugins like Wordfence or iThemes Security can do it for you:
1. Install a Plugin
Go to your WordPress dashboard and install Wordfence or iThemes Security.
2. Go to IP Blocking
Most plugins have a section for blocked IPs under their “Firewall” or “Security” tab.
3. Add IPs
Enter the IPs you want to block, hit save and the plugin will do the rest.
Leave a Reply