How to stop bots on WordPress

Basic4 min readUpdated

GET /learn/implementation/stop-bots-on-wordpress/ Accept text/html text/markdown

Short answer

Block xmlrpc.php if nothing uses it, rate limit wp-login.php and turn on two-factor login for admins, filter comment and form spam with Akismet or a honeypot, and add a firewall plugin such as Wordfence. Put a CDN or WAF in front so bots are stopped before they reach PHP. On WooCommerce stores, protect checkout and the Store API against card testing.

Bots know the default paths of a WordPress site and try them on every site they find: /wp-login.php, /xmlrpc.php, comment forms, plugin files with known vulnerabilities and, on shops, the WooCommerce checkout. Because the targets are the same on every install, the fixes are well known too.

How do you stop brute-force attacks on wp-login.php?

Limit login attempts. A plugin such as Wordfence or Limit Login Attempts Reloaded does it inside WordPress. A server rule does it before PHP starts, which is cheaper. On nginx, this counts only POST requests to the login page, so visitors who load the form are not counted:

nginx
map $request_method $wp_login_key {
    POST    $binary_remote_addr;
    default "";
}

limit_req_zone $wp_login_key zone=wplogin:10m rate=6r/m;

server {
    location = /wp-login.php {
        limit_req zone=wplogin burst=3 nodelay;
        limit_req_status 429;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }
}

The map and limit_req_zone lines go in the http context. nginx skips requests whose key is empty, which is how GET requests escape the limit. An exact location = match takes priority over your general PHP location, so copy the FastCGI lines from your existing PHP block; the socket path differs between systems.

Then reduce what a successful guess is worth. Turn on two-factor login for every administrator and editor, and do not use admin as a username. WordPress exposes author slugs, which often match usernames, at /?author=1 and through the REST API at /wp-json/wp/v2/users, so assume attackers know them. The difference between guessing one account and testing leaked passwords across many is covered in credential stuffing vs brute force vs password spraying.

Should you block xmlrpc.php?

XML-RPC is an older remote API. Its system.multicall method lets one request carry many login attempts, which gets around per-request login limits, and its pingback feature has been abused to send traffic at other sites. If nothing on your site needs it, block it at the server.

nginx:

nginx
location = /xmlrpc.php {
    deny all;
}

Apache 2.4, in .htaccess or the virtual host:

apache
<Files "xmlrpc.php">
    Require all denied
</Files>

Jetpack and some remote publishing apps use XML-RPC. If you rely on them, keep the file and rate limit it like wp-login.php instead.

How do you stop comment and form spam?

Akismet checks comments against a shared spam service, and many contact form plugins can send submissions through it as well. Add a hidden honeypot field to forms, which real visitors never fill in; see honeypots for bot detection. If spam still gets through, add an invisible challenge such as Cloudflare Turnstile through a plugin. How to stop bots from submitting forms covers server-side checks that work with any form plugin.

If you do not need comments, turn them off under Settings, Discussion. The same screen can close comments on posts older than a set number of days, which shrinks the target on an old blog.

Add a firewall plugin and a CDN in front

Wordfence is a common choice. It adds a firewall inside WordPress, login security with two-factor authentication, rate limiting and a malware scanner. The free version receives new firewall rules later than the paid one. Because it runs in PHP, each blocked request still costs some server work.

A CDN or WAF in front stops bots before they reach the server at all. Cloudflare's free plan with Bot Fight Mode is a common starting point, and on Pro and Business, Super Bot Fight Mode has a setting that keeps WordPress loopback requests working. The Cloudflare guide has rule examples, and the nginx and Apache guide covers server-level blocks.

Page caching also matters. Bots hitting cached pages cost little. Uncached endpoints cost the most: search (/?s=), the cart, admin-ajax.php and wp-json. Put your rate limits on those.

How do you protect WooCommerce checkout from bots?

The bot attack that costs WooCommerce stores most directly is card testing: scripts placing many small orders to find out which stolen cards work. They often skip the checkout page and post straight to the Store API at /wp-json/wc/store/v1/checkout. WooCommerce includes rate limiting for the Store API, and the setting "Rate limiting Checkout block and Store API" under WooCommerce, Settings, Advanced, Features turns it on for checkout. A limit keyed on IP address slows card testing, but attackers who rotate addresses get through.

Pair it with your payment provider's fraud rules, and watch for clusters of failed payments, guest orders with random email addresses and many cards sharing one BIN. How to stop card testing has the full checklist, and Kairal's guide to card testing on WooCommerce covers the store side in more detail.

Tools that help

StopBots is published by Kairal, which is one of the tools listed. The list is not a ranking.

  • Wordfence adds a firewall, login limits and two-factor login inside WordPress; the free version is enough for many small sites.
  • Akismet filters comment and form spam through a hosted service and suits any site that accepts comments.
  • Limit Login Attempts Reloaded is a free plugin that locks out addresses after repeated failed logins, for sites that want only that one feature.
  • Cloudflare puts bot settings and a WAF in front of the site, with a free plan that covers basic bot blocking.
  • Kairal for WooCommerce protects login, signup and checkout with device, network and behavioural signals, aimed at card testing and account abuse on stores.

Common questions

Should I disable xmlrpc.php in WordPress?

Disable it if you do not use Jetpack, remote publishing tools or an app that posts through XML-RPC, since those are its main users. After blocking it, test any plugin that connects your site to an outside service.

Does Wordfence stop bots?

Wordfence blocks known attack patterns, limits login attempts and can block addresses that break its rate limits. It runs inside WordPress, so every bot request still reaches PHP first. A CDN or server rule stops large volumes earlier and saves server resources.

How do I block bot traffic on WordPress for free?

Block xmlrpc.php, add a login limit through a plugin or your server, keep Akismet or a honeypot on forms, and put the site behind a free CDN plan with its bot setting on. Free versions of the main security plugins are often enough for small blogs and brochure sites.