Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Troubleshooting

WordPress Error Invalid Nonce: Causes and How to Fix It

WordPress Error Invalid Nonce: Causes and How to Fix It

Short answer

An invalid nonce error means WordPress blocked a request because its security token was expired, missing or made for a different session. Reload the page first, then clear cookies and log in again. Repeated errors usually come from cached forms, blocked cookies or a plugin bug.

Key takeaways

  • Nonces are security tokens that stay valid for up to 24 hours by default.
  • Cached pages with forms are the most common cause for visitors.
  • Logging in or out in another tab makes older tokens fail.
  • REST API cookie check failures need a fresh X-WP-Nonce header.
  • Never disable nonce checks; fix the cache, cookies or plugin instead.

What does the WordPress invalid nonce error mean?

An invalid nonce error means WordPress rejected a form, link or request because its one-time security token was missing, expired or did not match the logged-in user, so the action was blocked for safety.

A nonce is a short security code WordPress adds to forms, admin links and AJAX requests. It proves the request came from your own site and from the right user.

When the check fails, you may see one of several messages:

  • Invalid nonce or Nonce verification failed, often from a plugin
  • The link you followed has expired.
  • Are you sure you want to do this?
  • Cookie check failed, from the REST API

They all point to the same check. Our explainer on what a nonce is in WordPress covers the concept in more detail.

Why do WordPress nonces become invalid?

Nonces fail when the page was open too long, a cache served an old token, you logged in or out in another tab, cookies were blocked, or a plugin created or checked the token incorrectly.

SituationWhy the nonce failsFix
Page left open for many hoursToken expiredReload the page and try again
Form on a cached pageCache serves an old token to everyoneExclude the page or shorten cache life
Logged out or in another tabToken belongs to a different sessionReload after logging in
Cookies blocked or strippedWordPress cannot identify the userAllow cookies, check CDN and security rules
Mixed http and https or wwwCookies set for the wrong addressMatch site URL settings
Plugin bugWrong action name or missing tokenUpdate or report the plugin

How long does a WordPress nonce last?

By default a WordPress nonce stays valid for up to 24 hours, though it can expire after about 12 hours depending on when it was created, because WordPress checks it in two time windows.

WordPress splits the day into two halves, called ticks. A nonce works in the tick it was made and the one after.

Developers can change the lifetime with the nonce_life filter. Shorter lifetimes are more secure but cause more errors for slow users.

Nonces are also tied to the user and their login session. A token made for one user, or before a fresh login, will not work for another session.

The Nonces section of the Common APIs handbook explains how WordPress builds and checks them.

How do I fix an invalid nonce error quickly?

Reload the page to get a fresh token and try the action again; if that fails, log out, clear cookies for the site, log back in and retry in a single tab.

Most single errors disappear after a reload. The form simply had an old token.

If the error keeps coming back:

  1. Close extra tabs of your site's admin.
  2. Log out of WordPress.
  3. Clear cookies for your site only.
  4. Log back in and repeat the action.
  5. Test in a private window with browser extensions off.

If you see The link you followed has expired while uploading a theme or plugin, the real cause is often a file that is too large for the server. Our guide to the link you followed has expired covers that case.

Is caching causing invalid nonce errors?

Yes, page caching is the most common cause for visitors; when a page with a form is cached, everyone gets the same old token, which stops working once it expires.

This hits contact forms, comment forms, login forms and store pages. The form works for a while after the cache refreshes, then starts failing.

Fix it in one of these ways:

  • Exclude pages with forms from the page cache
  • Set the cache lifespan shorter than the nonce lifetime, such as 10 hours or less
  • Use form plugins that refresh tokens with AJAX
  • Purge the cache after changing forms

Some caching plugins already use a short default lifespan for this reason. Check your plugin's settings before changing them.

CDNs can cache HTML too. If you cache full pages at a CDN, apply the same rules there. Cloudflare's cache documentation explains how to bypass caching for specific paths.

Our guide on how to clear cache in WordPress covers purging for popular plugins and hosts.

Are cookies or site URLs breaking the nonce check?

When cookies are blocked or set for a different address, WordPress cannot match the nonce to your session, so the check fails even with a fresh token.

Logged-in nonces depend on your login cookie. Without it, WordPress treats you as a different user.

Common causes include:

  • WordPress Address and Site Address using different http, https or www versions
  • A security plugin or firewall stripping cookies
  • A browser privacy setting blocking cookies for the site
  • A CDN or proxy caching responses with cookies removed

Make sure both address fields in Settings > General match exactly. MDN's guide to HTTP cookies explains how domains and secure flags affect cookies.

If login itself also misbehaves, see our guide on a login page refreshing and redirecting.

The REST API returns rest_cookie_invalid_nonce when a logged-in request is missing the X-WP-Nonce header or sends an old token, so it cannot confirm the user.

The block editor, many admin screens and plugins use the REST API. When this check fails, saving posts or loading settings may fail with a 403 error.

Usual causes are a stale editor tab, caching of admin requests, or a plugin that sends requests without the right header.

Reload the editor first. If it continues, test with plugins disabled using the Health Check and Troubleshooting plugin, which only affects your own session.

Our guide on fixing a REST API error in Site Health covers broader REST problems.

Can a plugin cause invalid nonce errors?

Yes, a plugin that creates a nonce with one action name and checks it with another, or that caches its own tokens, will fail every time, and only an update or code fix solves it.

If the error appears only on one plugin's form or button, that plugin is the likely source.

Update the plugin first. Then search its support forum for the exact error text. If nobody has reported it, send the developer the message, page URL and steps to reproduce.

Store owners often see a related message in checkout or cart flows. Our guide on the WooCommerce session expired error covers that case.

How do developers fix nonce errors in their own code?

Create and check the nonce with the same action string, send it with every request, verify it with the matching helper, and avoid caching pages that embed user-specific tokens.

A typical AJAX pattern looks like this:

// Create the nonce and pass it to JavaScript.
wp_localize_script( 'my-script', 'myData', array(
    'nonce' => wp_create_nonce( 'my_action' ),
) );

// Check it in the AJAX handler.
check_ajax_referer( 'my_action', 'nonce' );

For REST requests from logged-in users, send a nonce made for the wp_rest action in the X-WP-Nonce header.

Remember that nonces are not passwords. Always check user permissions with current_user_can as well.

Our guide on how to use nonces in WordPress shows complete examples for forms and admin links.

For JavaScript requests, the guide to making AJAX requests in WordPress shows where the nonce fits in the full request.

Should I disable nonce checks to stop the error?

No, disabling nonce checks removes protection against forged requests, so attackers could trick logged-in users into changing settings or deleting content; fix the cause instead.

Nonces defend against cross-site request forgery. Without them, a malicious link could perform actions as you.

If a third-party plugin forces you to choose, replace the plugin. Security trade-offs like this are rarely worth it.

Frequently asked questions

What is a nonce in WordPress?

A nonce is a short security token WordPress adds to forms, links and requests. It confirms that an action came from your site and from the right logged-in user, which protects against forged requests from other websites.

Why does my contact form say invalid nonce?

The page with the form was probably cached, so visitors received an old token that has since expired. Exclude the form page from caching, shorten the cache lifespan or use a form plugin that refreshes its token automatically.

Is the invalid nonce error a security problem?

No, the error itself is WordPress protecting you by refusing a request it cannot verify. It becomes a problem only if it blocks normal use, in which case fix the cache, cookie or plugin issue behind it.

How do I fix Are you sure you want to do this in WordPress?

Reload the page and repeat the action, or log out and back in. If it happens while uploading a theme or plugin, the file is often too large for the server, so raise upload limits or upload the files another way.

Can I make WordPress nonces last longer?

Developers can change the lifetime with the nonce_life filter. Longer lifetimes reduce expired token errors but weaken protection slightly. Fixing caching and stale tabs is usually a better solution than extending the lifetime.

Sources

  1. Nonces WordPress Developer Resources
  2. nonce_life hook WordPress Developer Resources
  3. Using HTTP cookies MDN Web Docs
  4. Cache documentation Cloudflare
  5. Health Check & Troubleshooting WordPress.org

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.