On this page
What this issue is
WordPress protects forms, logins and AJAX requests with a nonce. A nonce is a short code tied to a time window and, for logged-out visitors, mostly to the site rather than to one person. The page prints it into the HTML, usually as a hidden field such as _wpnonce, or into a JavaScript variable. When the visitor submits, WordPress checks the code. If it is too old, the request fails.
The page looks fine. It loads fast and the form shows. The failure only appears when someone submits. They see a message like "Are you sure you want to do this?", "The link you followed has expired", a 403 error, or a spinner that never ends. Most people do not try again.
- Cache saves pageHTML stored with nonce inside
- Visitor loads pageGets the old cached copy
- Visitor submits formOld nonce sent to the server
- Lead or orderNever created
- Conversion trackingThank-you page never reached
The visitor does nothing wrong. The token in the cached page has already expired.
Example: illustrative numbers showing how acceptance drops once the cached copy is older than the nonce lifetime.
How to check if your site has it
Open the page logged out
Use a private window with no WordPress login cookie. Logged-in users often skip the cache, so testing while logged in hides the problem.
Look for a cache header
In browser DevTools, Network tab, click the page request. Look for headers such as
x-cache: HIT,cf-cache-status: HIT,x-litespeed-cache: hitorx-wp-cache. A hit means you are seeing a stored copy.Find the nonce in the source
View page source and search for
_wpnonce,nonceor your form plugin's token field. Note the value.Compare with a fresh load
Purge the cache, reload, and compare the value. If it is identical across many reloads for hours, it is baked into the cached page.
Submit after the cache has aged
Submit the form from a page copy older than 24 hours. If it fails with an expiry or 403 message while a fresh copy works, a stale nonce is the cause.
How to fix it
You have two routes. The simple one is to stop caching the page that holds the form. The better one for busy pages is to keep caching and have the token fetched fresh after the page loads. Start with the simple one.
Before
- Form page cached for days
- Nonce frozen in the HTML
- Submits fail after the token expires
After
- Form page excluded, or cache lifetime under 12 hours
- Token is fresh when the page loads
- Submits are accepted
Exclude the form page
In your caching plugin (WP Rocket: Advanced Rules > Never Cache URL(s); W3 Total Cache: Page Cache > Never cache the following pages; LiteSpeed Cache: Cache > Excludes > Do Not Cache URIs), add the URL of the page with the form.
Shorten cache lifetime
If you must cache it, set the cache lifespan under 12 hours (WP Rocket: Cache > Cache Lifespan; LiteSpeed: Cache > TTL). Preloading helps keep copies fresh.
Check form plugin settings
Some form plugins offer a setting to load tokens by AJAX or to disable nonce on public forms. Look in the plugin's settings or docs, and keep spam protection on.
Do not cache checkout and account pages
For WooCommerce, cart, checkout and my-account pages must be excluded. Most cache plugins do this by default, so check it is still on.
Purge everything
Clear the plugin cache, then any host or CDN cache, so old copies are gone.
Send no-cache headers on form pages
Add
Cache-Control: no-store(orprivate, no-cache) on pages that print a nonce. Make sure your CDN honours it.Or fetch the nonce after load
Cache the page, then request a fresh nonce from a small uncached endpoint and fill the hidden field with JavaScript. See the snippet below.
add_action('wp_ajax_nopriv_fresh_nonce', 'fg_fresh_nonce');
add_action('wp_ajax_fresh_nonce', 'fg_fresh_nonce');
function fg_fresh_nonce() {
nocache_headers();
wp_send_json_success(array('nonce' => wp_create_nonce('my_form_action')));
}document.addEventListener('DOMContentLoaded', function () {
var field = document.querySelector('input[name="_wpnonce"]');
if (!field) return;
fetch('/wp-admin/admin-ajax.php?action=fresh_nonce', { credentials: 'same-origin', cache: 'no-store' })
.then(function (r) { return r.json(); })
.then(function (j) { if (j.success) field.value = j.data.nonce; });
});How to confirm it's fixed
- Purge all caches (plugin, host, CDN).
- In a private window, load the form page and submit it. It succeeds.
- The response headers show no long-lived cache hit for the form page, or the nonce value changes between loads.
- Wait until the old cache lifetime would have passed, then submit again. It still succeeds.
- The test lead appears in your inbox and CRM, and the thank-you page loads.
- Your conversion tag fires on the thank-you page.
How to prevent it happening again
- Keep a list of pages with forms, checkouts and logins, and keep them in your cache exclusion rules.
- Keep cache lifetime under 12 hours wherever a nonce is printed.
- Re-check exclusions after changing cache plugins, hosts, CDN or themes, because settings often reset.
- Test the forms logged out after every plugin update and cache purge.
- Run a scheduled test submit so a failure is caught within a day, not after weeks.
How FunnelGuard handles this
FunnelGuard detects this today. A robot visitor loads your page as a logged-out visitor, fills in and submits the form on a schedule, and checks the result. When the submit fails, as it does with a stale nonce, the step is marked failed. The failure is re-checked from a second region before one alert goes out by email, Slack, Teams, WhatsApp, webhook or PagerDuty, with a screenshot and a likely cause.
The page loads normally, then the submit is rejected.
Questions people ask
Why does my WordPress form say "Are you sure you want to do this?"
That message usually means a nonce check failed. A common cause is a cached page that still holds an expired nonce. Exclude the form page from caching or shorten the cache lifetime, then purge the cache.
How long does a WordPress nonce last?
By default a WordPress nonce is valid for up to 24 hours, in two 12-hour windows. If your cached page is older than that, the token inside is no longer accepted. Keep cache lifetime under 12 hours on pages that print a nonce.
Why does my form work when I'm logged in but fail for visitors?
Many caching setups skip the cache for logged-in users, so you get a fresh page and a fresh token. Visitors get the stored copy with an old token. Test in a private window while logged out.
Should I exclude my contact page from the cache?
If the page prints a nonce and a failing submit costs you leads, yes. It is the simplest fix. The speed cost for one page is small compared with losing submissions.
Does WooCommerce checkout break with page caching?
It can if the cart, checkout or my-account pages are cached. Most cache plugins exclude them by default, but check that the rule is still active after plugin or host changes.
How do I fix a stale nonce without turning off caching?
Keep the page cached and load the nonce fresh after the page loads, using a small uncached AJAX endpoint that fills the hidden field. Make sure that endpoint is never cached.
How can I find out my form is failing before customers tell me?
Run a scheduled test that submits the form as a logged-out visitor. FunnelGuard does this and alerts you when the submit fails, with a screenshot and a likely cause.
Related issues
- CNV-380CSRF token expired, form rejects submitFix guide
- CNV-382Logged-in cache served to visitorsFix guide
- CNV-376Session cookie lost between stepsFix guide
- CNV-383Cookie consent state not respected after choiceFix guide
- CNV-377Cookie too large, server 400 errorFix guide
- CNV-378SameSite settings break iframe login/checkoutFix guide