Key points
- Spam comes in through three different doors (forms, comments, registrations): find out which one is open first, because the fix is different for each.
- Start with invisible protections (honeypot field, minimum fill time, submission limits) and only add a captcha where they aren’t enough.
- Over-aggressive filtering costs more than spam: test your forms after every change and keep an eye on what gets blocked.
“We get thirty emails a day offering us SEO services”, “our brochure site somehow has 4,000 registered users”, “the comments are full of casino links”. Some version of this lands in our inbox from almost every client whose WordPress site has been online for a few years. Spam is more than an annoyance. Real enquiries get buried, auto-replies to spam can hurt your domain’s email reputation, and mass-created accounts are sometimes the first step in exploiting a vulnerable plugin. The good news is that you can cut it down to almost nothing without making visitors pick out traffic lights. Below is the approach we follow, step by step, with the code you need if you handle your own forms.
Before fixing anything: find out where spam gets in
The most common mistake is installing a random “anti-spam” plugin. Spam arrives through different routes, and blocking one leaves the others wide open. Spend ten minutes sorting what you receive:
- Contact and quote forms (Contact Form 7, WPForms, Gravity Forms, Elementor, or a custom form): sales pitches, “backlink” offers, sometimes pure gibberish. This is the most common case.
- Comments: links in the comment body or the “website” field, usually on old posts where comments were left open and forgotten.
- Registrations: “subscriber” accounts piling up. They come from the “Anyone can register” setting, a WooCommerce shop that allows account creation, or a membership plugin.
- Spam that isn’t from your site at all: if messages land straight in your mailbox without going through a form, it’s your email address that has leaked. No WordPress setting will help; your mail filter is where to work.
A quick test: look at the headers of a message. One sent by your form usually carries the form’s name in the subject and is sent by your site. If it comes from an outside address and never mentions your site, it didn’t come from it.
On client projects we regularly find forgotten entry points along the way: an old newsletter sign-up form that’s no longer displayed but whose handler still responds, a test page published by accident, a theme that ships its own contact form. Bots don’t use your menus; they post directly to the URLs that process forms. What visitors can no longer see may still be exposed.
Invisible protections: put these in place first
Most form spam comes from simple bots that fill every field and submit in a fraction of a second. Three server-side checks that your visitors never notice stop the vast majority of it.
The honeypot field. Add a field hidden with CSS. A human never sees it and leaves it empty; a bot that fills everything fills it too. Hide it by moving it off-screen rather than with display: none, which some bots detect, and keep it out of keyboard navigation and screen readers so it doesn’t trip up people who use them.
<!-- Trap field: invisible to humans, filled in by most bots -->
<div class="hp-field" aria-hidden="true">
<label for="website_url">Leave this field empty</label>
<input type="text" id="website_url" name="website_url" tabindex="-1" autocomplete="off">
</div>
<input type="hidden" name="form_ts" value="<?php echo esc_attr( time() ); ?>">
<style>
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
</style>
A minimum fill time. Store the time the form was rendered in a hidden field; if the submission arrives less than three seconds later, it isn’t a person. Watch out for full-page caching: if the whole page is served from cache, the stored time is when the page was cached, and the check quietly stops working (the delay always looks long). In that case set the value with JavaScript on load, or exclude the page from the cache.
Simple content rules. More than two links in a quote request is rarely a customer. Avoid keyword blocklists, though: sooner or later you’ll reject a genuine prospect who mentions “crypto” or “loans” for perfectly good reasons.
Here’s how we combine these checks for a custom form:
function wts_form_looks_like_spam(): bool {
// 1. The trap field was filled in: bot
if ( ! empty( $_POST['website_url'] ) ) {
return true;
}
// 2. Submitted in under 3 seconds: no human types that fast
$ts = isset( $_POST['form_ts'] ) ? (int) $_POST['form_ts'] : 0;
if ( $ts === 0 || time() - $ts < 3 ) {
return true;
}
// 3. Message stuffed with links
$message = isset( $_POST['message'] ) ? wp_unslash( $_POST['message'] ) : '';
if ( preg_match_all( '~https?://~i', $message ) > 2 ) {
return true;
}
return false;
}
// In your form handler (admin-post.php, REST route, etc.)
if ( wts_form_looks_like_spam() ) {
// Pretend everything went fine: the bot learns nothing
wp_safe_redirect( add_query_arg( 'sent', '1', wp_get_referer() ) );
exit;
}
The key detail is the response: never tell the bot it was caught. It gets the same confirmation a human would and moves on, instead of trying variations until something gets through.
If you use a form plugin, check its settings before writing any code: most already offer a honeypot (often labelled “honeypot” or “anti-spam protection”) that just needs switching on. Contact Form 7 relies on add-ons for this; WPForms and Gravity Forms have it built in.
Captchas: when you actually need one, and which
If spam keeps coming despite all that, you’re dealing with smarter bots (that run JavaScript and wait a few seconds) or people paid to fill in forms. That’s when a captcha makes sense, but choose carefully.
- Cloudflare Turnstile: usually invisible or a single checkbox, free, no image puzzles. It’s our default choice today.
- hCaptcha: similar, with a free tier; image challenges show up more often.
- Google reCAPTCHA v3: invisible, returns a score you have to interpret yourself. It loads Google scripts on the pages concerned, which has implications for your cookie consent setup.
Whichever you pick, one rule never changes: verification happens on the server. The widget in the page produces a token; your code has to send it to the provider and reject the submission unless the answer is positive. We’ve audited sites where the captcha was displayed but never checked. It blocked nothing, because bots post straight to the handler without loading the page.
function wts_verify_turnstile(): bool {
$token = isset( $_POST['cf-turnstile-response'] )
? sanitize_text_field( wp_unslash( $_POST['cf-turnstile-response'] ) )
: '';
if ( $token === '' ) {
return false;
}
$response = wp_remote_post( 'https://challenges.cloudflare.com/turnstile/v0/siteverify', [
'timeout' => 5,
'body' => [
'secret' => TURNSTILE_SECRET, // defined in wp-config.php, never in the theme
'response' => $token,
'remoteip' => $_SERVER['REMOTE_ADDR'] ?? '',
],
] );
if ( is_wp_error( $response ) ) {
// Service unreachable: log it and apply your chosen policy
error_log( 'Turnstile: ' . $response->get_error_message() );
return false;
}
$data = json_decode( wp_remote_retrieve_body( $response ), true );
return ! empty( $data['success'] );
}
One decision to make deliberately: what happens if the captcha service doesn’t respond? Rejecting the submission keeps spam out but can cost you leads during an outage. On a quote form we often prefer to let it through and flag it in the email subject (“to check”) rather than lose a customer.
And don’t put a captcha everywhere. A search form doesn’t need one; a login form is better protected by a limit on attempts and two-factor authentication for admin accounts. Keep captchas for forms that send email or create data.
Comments and registrations: close what you don’t use
The most effective protection against comment spam is asking whether you need comments at all. On most business sites the answer is no: nobody comments on a services page, and genuinely discussed blog posts are rare. In Settings › Discussion, untick “Allow people to submit comments on new posts”, but note that it only applies to new content: existing posts keep their comments open. To close everything at once:
// Site without comments: close everything, including old posts
add_filter( 'comments_open', '__return_false', 20 );
add_filter( 'pings_open', '__return_false', 20 );
add_filter( 'comments_array', '__return_empty_array', 10 );
add_action( 'admin_menu', function () {
remove_menu_page( 'edit-comments.php' );
} );
// Also block direct posts to wp-comments-post.php
add_action( 'pre_comment_on_post', function () {
wp_die( 'Comments are closed.', '', [ 'response' => 403 ] );
} );
If comments are part of your site, keep them but put guardrails in place: hold each author’s first comment for moderation, close comments automatically after a few weeks (“Automatically close comments on posts older than…”), and add a filter such as Akismet, which checks comments against what it sees across a very large number of sites. Commercial use of Akismet requires a paid plan, so check which one fits.
Ask the same question about registrations. If your site has no members’ area, untick “Anyone can register” in Settings › General. We regularly find that box ticked on brochure sites, often since the day WordPress was installed, with thousands of useless accounts to show for it. On a WooCommerce shop accounts are useful, but you can limit creation to checkout and turn off open registration on the “My account” page.
While you’re there, check the default role for new users: it should be “Subscriber”. A higher default, changed by mistake or by a plugin at some point, turns every bot sign-up into an account that can publish.
On the server: rate-limit submissions and filter upstream
Some spam waves don’t even try to beat your filters: they fire hundreds of requests a minute. Even when rejected, those requests eat your hosting resources and can slow the site down for everyone. Two complementary measures help.
A per-IP submission limit. A few lines ensure the same address can’t submit more than five forms in ten minutes. No human gets near that threshold; bots do.
function wts_too_many_submissions( string $action, int $max = 5, int $window = 600 ): bool {
$ip = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
$key = 'wts_rl_' . $action . '_' . md5( $ip );
$nb = (int) get_transient( $key );
if ( $nb >= $max ) {
return true;
}
set_transient( $key, $nb + 1, $window );
return false;
}
if ( wts_too_many_submissions( 'contact' ) ) {
wp_die( 'Too many attempts, please try again in a few minutes.', '', [ 'response' => 429 ] );
}
Transients live in the database, or in the object cache if your host provides one (Redis, Memcached), which is plenty for a normal site. Behind a proxy or CDN, REMOTE_ADDR holds the proxy’s address rather than the visitor’s. Read the real address from the header your CDN sets, and only when the request genuinely comes from the CDN, otherwise anyone can forge that header.
A web application firewall upstream. A service such as Cloudflare (or your host’s firewall) can block or challenge suspicious requests before they ever reach WordPress, and rate-limit the endpoints that process forms (/wp-comments-post.php, /wp-admin/admin-ajax.php, your forms’ REST routes). Once volume gets high this is the most effective fix, because WordPress doesn’t even have to boot.
What we don’t recommend is blocking entire countries on reflex: bots run on servers everywhere, including in your own country, and you risk shutting out a travelling customer or a visitor on a VPN.
Clean up the backlog, then make sure real messages get through
With the doors closed, you’re left with the backlog: thousands of spam comments and unknown accounts. WP-CLI deals with it quickly, after a database backup:
# How many spam and pending comments?
wp comment list --status=spam --format=count
wp comment list --status=hold --format=count
# Empty the spam folder
wp comment list --status=spam --format=ids | xargs -r -n 100 wp comment delete --force
# Suspicious sign-ups: recent subscribers, to review before deleting anything
wp user list --role=subscriber --fields=ID,user_login,user_email,user_registered
--orderby=user_registered --order=DESC | head -50
# Targeted deletion once the list is checked (content reassigned to user 1)
wp user delete 1234 1235 1236 --reassign=1
Don’t bulk-delete users without looking at the list: real WooCommerce customers are also “subscribers” or “customers”. Filter on registration date (spam waves usually have an obvious start) and on clearly generated addresses.
Then comes the step people forget most often: checking that genuine enquiries still arrive. A badly tuned filter that blocks prospects costs more than the spam did, and it fails silently. After every change:
- send a test message yourself, on desktop and on mobile, from a browser without extensions;
- log rejected submissions (reason, date, message excerpt) instead of discarding them, and read that log during the first week;
- if your form also stores entries in the database (most plugins offer this), occasionally compare stored entries with what actually reaches your inbox: a gap points to a delivery problem, not a spam one.
That last point matters. When a client tells us “the spam has stopped, but so have the enquiries”, the anti-spam is rarely to blame. More often, email sending itself has broken. A WordPress site that sends through the server’s mail function, without authenticated SMTP or SPF and DKIM records, gets its messages filtered by mail providers. Fix delivery before you suspect your filters.
FAQ
My form plugin already has anti-spam. Why do I still get spam?
Usually because it isn’t enabled on every form, or because the spam comes in through another door (comments, an old form, registrations). Check each form one by one, then look at where the messages you receive really come from.
Does a captcha hurt conversions?
Image-recognition captchas clearly put some visitors off, especially on mobile. Invisible or single-checkbox options are far less intrusive. That’s why we start with invisible protections and only add a captcha when they fall short.
Should I delete all the subscriber accounts created by bots?
Yes, once you’ve checked them: they clutter the database, distort your user lists and widen the attack surface if a plugin has a flaw affecting logged-in users. Back up first, then delete in targeted batches rather than in one sweeping command.
Can spam hurt my SEO?
Published comments full of links to dubious sites lower the perceived quality of your pages, and mass-generated profile pages can end up indexed. Form submissions aren’t public, so they have no direct effect on search rankings.
Inbox flooded, or worried you’re losing real enquiries? We audit your forms and put effective protection in place without getting in your visitors’ way. Get in touch.



