Seeing “Invalid nonce” or “Nonce verification failed” when submitting a form, uploading media, or checking out? This usually means the page served an expired or mismatched security token due to caching, authentication, or route issues. Use the checklist below to refresh tokens, bypass caches for dynamic pages, and verify the request is sent with the correct headers.
I’m getting “Invalid nonce” / “Nonce verification failed” on WordPress. How do I fix it?
Work through these in order. Most sites recover by steps 1–3.
admin-ajax.php or /wp-json/.Open your browser DevTools → Network. Submit the form and check the request:
_wpnonce) in POST data.X-WP-Nonce (or _wpnonce) for authenticated actions.# Example REST call with a nonce header
curl -i -X POST https://example.com/wp-json/your-namespace/v1/action \
-H "X-WP-Nonce: <nonce>" \
-H "Content-Type: application/json" \
--data '{"ok":true}'
rest_api_init.?wc-ajax=*).Classic form (admin-ajax):
// Output form field
wp_nonce_field( 'my_action', 'my_nonce' );
// Verify on submit
if ( ! isset( $_POST['my_nonce'] ) || ! wp_verify_nonce( $_POST['my_nonce'], 'my_action' ) ) {
wp_send_json_error( 'Invalid nonce' );
}
REST request (cookie auth): enqueue a script with a localized nonce, then send it via X-WP-Nonce. See REST auth docs for details.
Default nonce lifetime is about a day. If users keep a form open for many hours, you can extend lifetime temporarily (security trade‑off!):
add_filter( 'nonce_life', function( $l ) { return 2 * DAY_IN_SECONDS; } );
Prefer a UX fix (auto-refresh nonce before submit) over a permanent lifetime increase.
_wpnonce or X-WP-Nonce and matches the correct action.If you’re still stuck, capture a failing request (headers + response) and we can pinpoint whether it’s a stale page, missing header, or server block.
WooCommerce checkout shows “Invalid nonce”. Any WooCommerce-specific tips?
Yes, checkout pages are sensitive to caching and mixed domains.
?wc-ajax=* from all caches/CDNs.If the error persists only with a specific gateway, test with it disabled to confirm, then contact that gateway’s support.
WP Assistant is a free tool created by Atiba Software, a WordPress design and development company located in Nashville, TN. If you need more personalized WordPress assistance let us know, and we’ll get back to you ASAP!