Short answer: To use Cloudflare Turnstile on WordPress, create a widget in the Cloudflare dashboard, add the site key to your forms with a plugin or the cf-turnstile div, and verify every token on the server with the siteverify API using your secret key. Forms are accepted only when Cloudflare confirms success. Test first with Cloudflare’s test keys.
Key takeaways
- Turnstile is a free CAPTCHA alternative that usually needs no puzzles from real visitors.
- The widget only creates a token; server-side verification with siteverify is what actually blocks bots.
- Plugins cover login, comments, WooCommerce and popular form builders; custom forms need about thirty lines of PHP.
- Tokens expire after 300 seconds and work once, so reset the widget after a failed submission.
- Combine Turnstile with a honeypot, minimum fill time, nonces and rate limits.

Spam through WordPress forms is constant: fake leads, comment spam, credential stuffing on wp-login.php and bot registrations in WooCommerce. Classic CAPTCHAs stop some of it but annoy real customers, especially on mobile. Cloudflare Turnstile solves the problem differently: most visitors never see a puzzle, and bots that skip the widget are rejected on the server.
I use Turnstile on a production booking form that emails leads to two inboxes, alongside a honeypot, a minimum fill time and rate limits. This guide covers both routes: a plugin for standard WordPress forms, and clean custom code for your own forms and REST endpoints.
What is Cloudflare Turnstile and how does it work?
Cloudflare Turnstile is a CAPTCHA replacement that runs lightweight, non-intrusive challenges in the browser to tell humans from bots. When it is satisfied, it adds a token to your form. Your server sends that token with your secret key to Cloudflare’s siteverify endpoint, which confirms whether it is valid.
Site key: the public key used in the widget on your page. It identifies your widget and is safe to expose.
Secret key: the private key your server uses to verify tokens. Never put it in HTML, JavaScript or a public repository.
Token: the value Turnstile places in the hidden field cf-turnstile-response. It is valid for 300 seconds and can be redeemed once.
Turnstile vs reCAPTCHA vs honeypots
Turnstile is free, privacy-focused and rarely shows puzzles. reCAPTCHA is widely supported but sends more data to Google and can show image challenges. Honeypots are invisible and cost nothing but stop only simple bots. The strongest setup combines Turnstile with a honeypot and server-side checks.
| Method | User friction | Stops advanced bots | Notes |
|---|---|---|---|
| Cloudflare Turnstile | Very low | Yes, with server verification | Free; no Cloudflare proxy required |
| reCAPTCHA v2 | Medium to high | Mostly | Image puzzles for suspicious traffic |
| reCAPTCHA v3 | None visible | Mostly | Score-based; you choose thresholds |
| Honeypot field | None | No | Great extra layer, not enough alone |
| Minimum fill time | None | Partly | Rejects instant bot submissions |
Which Turnstile widget mode should you choose?
Turnstile offers three widget modes. Managed mode, the default, decides automatically whether to show a checkbox. Non-interactive mode shows the widget but never asks the visitor to click. Invisible mode hides the widget entirely. Managed suits most forms; choose invisible only when the design truly requires it.
| Mode | What visitors see | Best for |
|---|---|---|
| Managed | Usually a short loading state; a checkbox only when needed | Contact, booking and registration forms |
| Non-interactive | A visible widget that never needs a click | Forms where any click would hurt conversion |
| Invisible | Nothing | Custom designs; tell users the form is protected |
Step 1: create a Turnstile widget in Cloudflare
In the Cloudflare dashboard, open Turnstile, add a widget, give it a name, add every hostname where it will run (for example example.com and www.example.com), and choose Managed mode unless you have a reason for Non-interactive or Invisible. Copy the site key and secret key.
Your domain does not need to use Cloudflare DNS or proxying for Turnstile to work. Keep the secret key somewhere safe, such as a password manager, and add it to WordPress in the next step.
Step 2 (option A): use a plugin for standard forms
For login, registration, password reset, comments, WooCommerce checkout and popular form builders, a dedicated plugin is the quickest route. Simple Cloudflare Turnstile on WordPress.org supports WordPress core forms, WooCommerce, Contact Form 7, WPForms, Elementor Pro forms and others.
- Install and activate the plugin.
- Paste the site key and secret key in its settings.
- Choose which forms to protect, starting with login and registration.
- Test each form while logged out, in a private window.
Protecting wp-login.php with Turnstile is a good complement to server-level defences such as fail2ban and nginx rate limiting.
Step 2 (option B): add Turnstile to a custom form
For forms you built yourself, store the keys as options, add the widget to the form, and verify the token on submission. Keeping keys in the database or in wp-config.php constants avoids committing them to a theme repository.
# Store keys as options (never hard-code the secret in theme files)
wp option add sz_turnstile_site "0x4AAAAAAA..." # site key (public)
wp option add sz_turnstile_secret "0x4AAAAAAA..." --autoload=no # secret key
<form method="post" action="">
<input type="text" name="name" required>
<input type="email" name="email" required>
<textarea name="message" required></textarea>
<!-- Turnstile widget: the site key is public -->
<div class="cf-turnstile" data-sitekey="<?php echo esc_attr( get_option('sz_turnstile_site') ); ?>"
data-theme="light" data-action="contact"></div>
<?php wp_nonce_field( 'contact_form', 'contact_nonce' ); ?>
<button type="submit">Send</button>
</form>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
The data-action value labels the widget, and Cloudflare returns it during verification, so you can confirm a token was issued for this specific form.
Step 3: verify the token on the server
Server-side verification is the step that actually stops bots. POST the token, your secret key and optionally the visitor’s IP to siteverify, and accept the submission only if the response says success is true. Treat network errors as failures so the form fails closed.
<?php
/**
* Verify a Turnstile token server-side. Returns true only on a confirmed success.
*/
function sz_turnstile_verify( $token, $expected_action = '' ) {
$secret = get_option( 'sz_turnstile_secret' );
if ( ! $secret || ! $token ) {
return false;
}
$res = wp_remote_post( 'https://challenges.cloudflare.com/turnstile/v0/siteverify', array(
'timeout' => 10,
'body' => array(
'secret' => $secret,
'response' => $token,
'remoteip' => $_SERVER['REMOTE_ADDR'] ?? '',
),
) );
if ( is_wp_error( $res ) ) {
return false; // fail closed if Cloudflare is unreachable
}
$data = json_decode( wp_remote_retrieve_body( $res ), true );
if ( empty( $data['success'] ) ) {
return false;
}
if ( $expected_action && ( $data['action'] ?? '' ) !== $expected_action ) {
return false; // token was issued for a different form
}
return true;
}
<?php
add_action( 'init', function () {
if ( 'POST' !== $_SERVER['REQUEST_METHOD'] || empty( $_POST['contact_nonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_POST['contact_nonce'], 'contact_form' ) ) {
wp_die( 'Session expired, please reload the page.' );
}
$token = sanitize_text_field( $_POST['cf-turnstile-response'] ?? '' );
if ( ! sz_turnstile_verify( $token, 'contact' ) ) {
wp_die( 'Verification failed, please try again.', 403 );
}
// ...validate fields, then send the email or store the lead
} );
From my own work: On my booking endpoint the order matters: I check the honeypot and the minimum fill time first, then the rate limit, and only then call siteverify. Cheap checks reject most junk before the network call, and the Turnstile verification protects against the bots that pass them.
If your site is behind Cloudflare, make sure REMOTE_ADDR holds the real visitor address; see nginx real IP behind Cloudflare. Otherwise you are sending Cloudflare edge addresses to siteverify, which is harmless but less useful.
How to use Turnstile with REST API and AJAX forms
Single-page forms that submit with fetch work the same way: read the token from the hidden field, send it with the request body, and verify it in your REST callback before doing anything else. Because tokens are single-use, call turnstile.reset() after a failed request so the next attempt gets a fresh token.
// Front end: send the token with a REST/AJAX request
const token = document.querySelector('[name="cf-turnstile-response"]').value;
const r = await fetch('/wp-json/myplugin/v1/lead', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, email, message, turnstile: token })
});
if (!r.ok) { turnstile.reset(); } // tokens are single-use: get a fresh one
In the REST route’s callback, call sz_turnstile_verify() with the token and return a 403 response when it fails. Combine it with a nonce for logged-in actions, and keep rate limiting on the route.
Step 4: test with Cloudflare test keys
Cloudflare publishes dummy keys for testing. Use the always-pass and always-fail pairs on staging or local development to confirm both paths of your code, then switch to your real keys for production. Real keys are bound to the hostnames you listed in the widget.
Site key (always passes): 1x00000000000000000000AA
Site key (always blocks): 2x00000000000000000000AB
Secret key (always passes): 1x0000000000000000000000000000000AA
Secret key (always fails): 2x0000000000000000000000000000000AA
Test these cases: a normal submission, a submission with the widget removed, a reused token, an expired token after five minutes, and a submission when siteverify is unreachable.
Content Security Policy and caching considerations
If your site sends a Content-Security-Policy header, allow scripts and frames from challenges.cloudflare.com, or the widget will not render. Full-page caching is fine because the token is generated in the browser, but never cache the response of the form handler itself.
# If you send a Content-Security-Policy header, allow Turnstile
script-src 'self' https://challenges.cloudflare.com;
frame-src https://challenges.cloudflare.com;
My guide to nginx security headers for WordPress shows how to build a CSP without breaking third-party widgets.
How do you protect WooCommerce with Turnstile?
WooCommerce stores attract fake account registrations, card-testing attacks on checkout and password reset abuse. Add Turnstile to the My Account login and registration forms, the lost password form and, if you see card testing, the checkout. Test the full checkout flow on mobile after enabling it, including payment gateway redirects.
- Registration: the most common bot target; protect it first.
- Checkout: protect it when you see bursts of failed payments from new accounts, a typical sign of card testing.
- Express payments: some wallet buttons bypass the checkout form; rely on gateway fraud tools there.
- Rate limits: keep server-level limits on checkout and login as an extra layer.
Is Turnstile privacy-friendly and GDPR compliant?
Cloudflare positions Turnstile as a privacy-preserving alternative to CAPTCHAs: it does not use visitor data for ad targeting and does not require tracking cookies. You should still mention it in your privacy policy, because it processes technical data such as the IP address and browser signals to detect bots, and you remain responsible for your own compliance assessment.
Layered spam protection for WordPress forms
Turnstile is strongest as one layer of several. Each layer catches different attackers, and together they keep false positives low for real visitors.
- Honeypot: a hidden field that humans never fill.
- Minimum fill time: reject forms submitted faster than a human could type.
- Nonce or signed token: proves the form came from your page.
- Rate limiting: limit submissions per IP and per email.
- Turnstile: verified human check.
- Validation: strict server-side checks on every field.
Troubleshooting Turnstile on WordPress
| Symptom | Likely cause | Fix |
|---|---|---|
| Widget does not appear | Script blocked or CSP | Allow challenges.cloudflare.com; check console errors |
| Error 110200 | Hostname not allowed | Add the exact hostname to the widget |
| invalid-input-secret | Wrong or missing secret | Check the stored option or constant |
| timeout-or-duplicate | Token reused or older than 300 s | Reset the widget before each retry |
| Works logged in, fails logged out | Cached page with stale nonce | Exclude the form page from cache or refresh nonces |
Turnstile checklist
- Widget created with all hostnames.
- Secret key stored server-side only.
- Widget on every public form, including login and registration.
- Server verifies every token and fails closed.
- Action names checked per form.
- Widget reset after failed submissions.
- CSP allows challenges.cloudflare.com.
- Honeypot, fill time, nonce and rate limits in place.
Want this done on your own server or site?
I am Saizul Amin, a web developer and technical SEO consultant. I set up and harden VPS servers, migrate WordPress sites, fix indexing problems and build automations. See my portfolio or get in touch.
FAQ
What is Cloudflare Turnstile?
Cloudflare Turnstile is a free CAPTCHA alternative that checks whether a visitor is human without asking them to solve puzzles in most cases. It runs small, privacy-friendly browser challenges and gives your form a token that your server verifies with Cloudflare before accepting the submission.
Is Cloudflare Turnstile free?
Yes, Turnstile has a free plan that covers most websites, and you do not need to proxy your site through Cloudflare to use it. You only need a Cloudflare account to create a widget and get the site key and secret key.
Do I need a plugin to use Turnstile on WordPress?
No. Plugins such as Simple Cloudflare Turnstile add it to login, registration, comments, WooCommerce and popular form plugins with a few clicks. For custom forms or REST endpoints, adding the widget and a small server-side verification function is straightforward and avoids an extra plugin.
Why is server-side verification required?
The widget only produces a token in the browser. A bot can skip the widget and post directly to your form handler, so your server must send the token to Cloudflare’s siteverify endpoint and reject the request unless Cloudflare confirms success. Without that step Turnstile protects nothing.
How long is a Turnstile token valid?
A Turnstile token is valid for 300 seconds and can be redeemed only once. If a form is open for a long time, or a submission fails and the user retries, reset the widget to get a new token before the next submission.
Does Turnstile replace other spam protection?
It is a strong layer, but combine it with a honeypot field, a minimum fill time, nonces, rate limiting and server-side validation. Layered protection stops both simple bots and determined spammers, and keeps working if one layer is bypassed.
Sources
- Cloudflare Turnstile: Get started
- Cloudflare Turnstile: Server-side validation
- Cloudflare Turnstile: Testing
- Cloudflare Turnstile: Client-side rendering
- WordPress Developer Resources: wp_remote_post()
- WordPress.org plugin: Simple Cloudflare Turnstile

Saizul Amin is a web developer, AI automation engineer and technical SEO consultant from Dhaka, Bangladesh (B.Sc. in CSE, BUBT). Since 2017 he has worked in digital marketing, WordPress, IT infrastructure and server administration, including the bilingual SHR Bangladesh website for DGHS, WordPress sites for UK and US clients, and the ShobFree tools platform. He runs this blog on his own Ubuntu VPS with nginx, Redis and CloudPanel, and tests the guides here on it. Portfolio: saizul.com

