Lab-tested: WordPress 6.8.3 + PHP 8.3.28 + Apache 2.4.65 (lab) · 2 Dec 2026 · Reproduced and fixed on a real WordPress
Fix Box — Try This First (10 Seconds)
A WordPress 401 is almost never the login form. First, check which door you hit: REST API requests need an Application Password for Basic auth, not your account password.
Second, cookie-based REST calls need the X-WP-Nonce header or WordPress treats you as logged out. Third, if the 401 carries a Basic challenge with a realm, an Apache or hosting layer in front of WordPress is asking — fix it there, not in wp-admin.
Still stuck? Walk the 401 Decision Tree or start from the pillar 401 Unauthorized: Causes and How to Fix It.
Table of Contents
- WordPress Has Three Different Doors
- The Exact Messages (Verbatim from Our Lab)
- Cause 1: REST Request Without Authentication
- Cause 2: Account Password Used as REST Basic Auth
- Cause 3: Cookie Auth Without the REST Nonce
- Cause 4: Apache or Hosting Layer in Front of WordPress
- Cause 5: Application Passwords Unavailable (No HTTPS)
- Our Lab Reproduction
- The Fix, Step by Step
- What Did Not Work
- Prevention
- FAQ
- Sources and Date
- References
WordPress Has Three Different Doors
WordPress authentication confuses people because three separate mechanisms guard three separate doors. The login form uses cookies and answers a wrong password with HTTP 200 and an error message — not a 401.
The REST API accepts cookie auth plus a nonce, or Basic auth with an Application Password. And in front of both, Apache .htaccess rules or hosting panels can demand their own Basic credentials and return a real 401 before WordPress even loads.
Each door fails differently and is fixed differently. Our lab ran a real WordPress 6.8.3 and reproduced every door's failure. Match your capture against the verbatim responses below before changing anything.
The Exact Messages (Verbatim from Our Lab)
These are real responses from WordPress 6.8.3 on Apache 2.4.65 in our lab on 2 Dec 2026, sanitized of lab credentials:
HTTP/1.1 401 Unauthorized
{"code":"rest_not_logged_in","message":"You are not currently logged in.","data":{"status":401}}
HTTP/1.1 401 Unauthorized
{"code":"rest_cannot_create","message":"Sorry, you are not allowed to create posts as this user.","data":{"status":401}}
HTTP/1.1 401 Unauthorized
Server: Apache/2.4.65 (Debian)
WWW-Authenticate: Basic realm="Lab Folder"
The JSON code field is your diagnosis. rest_not_logged_in means no acceptable credentials arrived.
rest_cannot_create after a cookie login usually means the nonce was missing, so WordPress silently treated you as user 0. A Basic challenge with a realm means the web server layer, not WordPress, is talking.
Cause 1: REST Request Without Authentication
Endpoints like /wp-json/wp/v2/users/me require a logged-in user. Our lab case 1 sent no credentials and got 401 with rest_not_logged_in.
The same endpoint with a correct Application Password returned 200 with the user object (case 4). Wrong Application Password: 401 again (case 3).
If your integration "worked in the browser" it was riding your login cookie. Scripts and external tools have no cookie. They need Application Passwords (Cause 2) or a proper auth plugin.
Cause 2: Account Password Used as REST Basic Auth
Since WordPress 5.6, REST Basic auth accepts Application Passwords, generated per user under Users → Profile. Your normal account password does not work.
Our lab case 2 proved it: Basic auth with the correct account password still returned 401. Case 4 with a generated Application Password returned 200.
Generate one Application Password per integration and name it after the tool. Revoking a leaked one then breaks only that tool. The REST API Handbook shows the curl shape: curl --user "USERNAME:APP_PASSWORD" https://HOST/wp-json/wp/v2/users/me.
Cause 3: Cookie Auth Without the REST Nonce
Inside wp-admin, JavaScript calls use your login cookie plus a nonce sent as the X-WP-Nonce header (action wp_rest). Without the nonce, WordPress deliberately sets the current user to 0 to prevent CSRF, turning the request unauthenticated even though you are logged in.
Our lab case 5 logged in with cookies and POSTed without a nonce: 401 rest_cannot_create. Case 6 added X-WP-Nonce and got 201 Created.
This bites custom Ajax code and headless setups that reuse browser cookies. Pass the nonce on every request, as a header (the handbook notes headers are the most reliable carrier, especially for DELETE).
If you are building an external integration, skip cookies entirely and use Application Passwords.
Cause 4: Apache or Hosting Layer in Front of WordPress
A 401 with WWW-Authenticate: Basic realm="..." and an Apache Server header never reached WordPress. Our lab case 7 protected a folder with .htaccess AuthType Basic: no credentials → 401 with realm "Lab Folder"; correct Apache credentials → 200 (case 8). WordPress was not involved in either response.
Hosts use this to protect wp-admin, staging sites, or whole directories. The fix lives in the hosting panel or .htaccess file: correct the AuthUserFile path, regenerate the password file, or remove the rule if it was left over from staging.
A path that points at a moved .htpasswd file makes every password fail. Security plugins can add similar layers; if the realm names your host or a plugin, start there.
Cause 5: Application Passwords Unavailable (No HTTPS)
Application Passwords require HTTPS (or a local environment). On a plain-HTTP site the Application Passwords section may not even appear in the profile, and Basic auth attempts fail.
Our lab ran on localhost with WP_ENVIRONMENT_TYPE set to local, which is the documented exception. Production sites should fix the certificate instead of working around it.
Also check the user: Application Passwords are per user, and the user needs the capability for the action. A subscriber's Application Password authenticates fine and still cannot create posts.
Authentication success plus capability failure surfaces as rest_cannot_create, which is why that code appears in two different causes.
Our Lab Reproduction
Stack: WordPress 6.8.3, PHP 8.3.28, Apache 2.4.65, MariaDB 11, in Docker on our lab machine, tested 2 Dec 2026. Nine cases: REST without auth, account password as Basic, wrong and correct Application Passwords, cookie POST with and without nonce, Apache folder protection, and the login form with a wrong password.
Full captured output is stored with this package as lab evidence, with lab credential values sanitized.
The before/after pair below is verbatim lab output:
# BEFORE (cookie login, POST without X-WP-Nonce)
HTTP/1.1 401 Unauthorized
{"code":"rest_cannot_create","message":"Sorry, you are not allowed to create posts as this user.","data":{"status":401}}
# AFTER (same cookies + X-WP-Nonce header)
HTTP/1.1 201 Created
Honest lab note: this is a clean WordPress with no security plugins. Real sites add plugin layers (login limiters, WAF rules, 2FA) that produce their own 401s and lockouts.
The three core doors and their error codes are the portable part; check your security plugin's logs when the core causes do not match.
The Fix, Step by Step
- Capture the response and read the
codefield or the challenge realm:
curl -si https://your-site.example/wp-json/wp/v2/users/me/
- For scripts, generate an Application Password (Users → Profile → Application Passwords) and test:
curl -si --user "USERNAME:APP_PASSWORD" https://your-site.example/wp-json/wp/v2/users/me/
- For in-admin JavaScript, send the nonce with every request:
fetch(wpApiSettings.root + 'wp/v2/posts', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': wpApiSettings.nonce },
body: JSON.stringify({ title: 'Hello', status: 'draft' })
});
- If the challenge realm names a folder or your host, fix the
.htaccessAuthTypeblock or hosting panel protection instead of WordPress. Verify with the Apache credentials, then the WordPress ones, in that order.
What Did Not Work
Our first lab run used default plain permalinks and REST URLs without a trailing slash. WordPress answered 301 redirects and, for POST, fell through to the homepage HTML with 200.
No auth diagnosis is possible against a redirect. Pretty permalinks plus trailing-slash REST URLs fixed the lab; on real sites, always capture with curl -si and read the status line before the body.
Using the account password for REST Basic auth failed in the lab even though the password was correct. WordPress simply does not accept it there.
And the login form with a wrong password returned HTTP 200 with an error banner (lab case 9), not a 401. If your monitoring reports "401 on login", you are looking at a server-layer challenge, not the form.
Retrying the cookie POST without a nonce failed identically. WordPress will not "warm up" to a nonce-less request; the user stays 0 until the nonce arrives.
Prevention
One Application Password per integration, named and revocable. HTTPS everywhere so Application Passwords stay available.
Log REST code values on failures, not just status codes. Document which layer protects wp-admin (host panel, plugin, or .htaccess) so the next 401 starts at the right door.
For the full cross-platform flow see the pillar 401 Unauthorized: Causes and How to Fix It and the 401 Checker. Related: 401 Basic Auth Failures and Nginx 401 Errors.
FAQ
Why does the REST API return 401 when I am logged in? Cookie auth needs the X-WP-Nonce header.
Without it WordPress treats the request as user 0. Add the nonce, or use an Application Password for external tools.
Can I use my WordPress password for REST Basic auth? No.
Since 5.6, REST Basic auth requires an Application Password generated in your profile. The account password returns 401 even when correct.
Why is there no Application Passwords section in my profile? Usually the site is not on HTTPS, or a plugin/filter disabled the feature. Fix HTTPS first; Application Passwords need it outside local environments.
The 401 asks for a username and password in a browser popup. Is that WordPress? No. A browser Basic popup with a realm is Apache, Nginx, or your host asking. Fix it at that layer; wp-admin credentials will not satisfy it.
Does a wrong wp-login password return 401? No. The login form returns HTTP 200 with an error message.
A real 401 around login comes from a server or plugin layer in front of the form.
Sources and Date
Lab tests run 2 Dec 2026 on WordPress 6.8.3, PHP 8.3.28, Apache 2.4.65, MariaDB 11 (Docker, lab machine). Response captures in this article are from that run, sanitized of lab credential values. Documentation references verified live on 2 Dec 2026.
References
- WordPress REST API Handbook, Authentication (cookie nonces and Application Passwords): https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
- RFC 9110, HTTP Semantics, Section 15.5.2 (401 Unauthorized): https://www.rfc-editor.org/rfc/rfc9110.html
- RFC 7617, The 'Basic' HTTP Authentication Scheme: https://www.rfc-editor.org/rfc/rfc7617.html
- MDN Web Docs, 401 Unauthorized: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401
- MDN Web Docs, WWW-Authenticate: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate






Leave a Reply