Skip to content

Fix "Cookies are blocked" on the WordPress login

Fix the WordPress login errors "Cookies are blocked due to unexpected output" and "Cookies are blocked or not supported by your browser" and get back into wp-admin. You will tell the two messages apart, find where the test cookie gets lost, and apply the matching fix in a safe order.

You type the right username and password on wp-login.php, and WordPress answers with “Cookies are blocked due to unexpected output” or “Cookies are blocked or not supported by your browser”. Clearing the browser cache rarely helps, because each message comes from its own check inside WordPress. “Unexpected output” means a PHP file printed text too early. “Not supported by your browser” usually means you are logging in on a different host than WordPress expects, such as www against no www. When the host matches, a cookie setting in wp-config.php or a cache in front of the login page is the next suspect, and the steps below test each one in order.

What you’ll accomplish

  • Match the exact message to the check in WordPress that produced it.
  • Compare the address you log in on with the siteurl and home settings.
  • Read the Set-Cookie header of the login page with curl and in the browser’s developer tools.
  • Find a cookie constant, a cache or a firewall rule that drops the test cookie.
  • Prove from the command line that the test cookie makes the round trip, then log in.

Prerequisites

You need SSH or cPanel Terminal access as the site’s account user, plus a copy of wp-config.php before you edit it. WP-CLI (the wp command, which reads and changes WordPress settings from the shell) makes steps 3 and 7 faster. Each of those steps also gives a manual route.

The commands use https://www.example.com as the site. Replace it with your own address, exactly as you type it in the browser. The two error messages and the cookie logic described here match current WordPress core (6.x and 7.x).

How it works

Every time wp-login.php loads, WordPress sends a test cookie named wordpress_test_cookie with the value “WP Cookie check”. It is a session cookie, so it disappears when the browser closes. It is marked HttpOnly, which hides it from page scripts. It is also marked Secure when WordPress builds its own login address with https, which tells the browser to keep it for encrypted connections only.

Three settings shape that cookie:

  • Domain comes from the COOKIE_DOMAIN constant. By default it is an empty string, so the cookie belongs to the exact host that served the page, and example.com and www.example.com count as different hosts.
  • Path comes from COOKIEPATH, which WordPress derives from the home address. When SITECOOKIEPATH (derived from siteurl) differs, WordPress sets a second copy on that path too.
  • Form target is the siteurl host. The login form posts to siteurl plus /wp-login.php, whatever host you typed in the address bar.

The form also carries a hidden field, testcookie=1. When you submit it without an existing login cookie, WordPress runs two checks in this order.

  1. If PHP has already sent output to the browser, setcookie() can no longer add headers. WordPress shows “Cookies are blocked due to unexpected output”.
  2. Otherwise, if the form sent testcookie=1 and the test cookie is missing from the request, WordPress shows “Cookies are blocked or not supported by your browser”.

A correct password does not get you past either check. The second check only proves the cookie was lost somewhere between the first page load and the form submit. The diagram shows the three places where that happens.

The WordPress login as four steps. Step 1 loads the login page, which sends Set-Cookie wordpress_test_cookie; a warning beside it says a cached copy means Set-Cookie never reaches you. Step 2 is the browser storing the cookie; the warning says the browser can refuse it for a wrong domain or a Secure cookie on http. Step 3 submits the form with testcookie=1; the warning says the cookie is not sent back when the form posts to another host such as www, or when a WAF strips it. Step 4, highlighted, is wp-login.php checking. It branches three ways: headers_sent true gives the unexpected output message, a missing test cookie gives the not supported message, and an arriving test cookie logs you in.

Here is what each message points to:

Message ends withCheck that failedWhere to look first
“due to unexpected output”Output was already sentPHP files, notices on screen
“not supported by your browser”Test cookie did not come backSite address, wp-config.php, cache, firewall, browser

Step-by-step

Work through the steps in order. They go from the quickest, safest checks to the ones that change the site.

1. Read the exact message. Copy the full red error text from the login box. If it ends with “due to unexpected output”, a PHP file, a plugin or a PHP notice printed text before WordPress could send its headers. Check the start of the login page:

curl -s https://www.example.com/wp-login.php | head -n 4

Expected output on a healthy site:

<!DOCTYPE html>
	<html lang="en-US">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

A blank line, a byte order mark (three invisible bytes some editors add to the start of a file) or a “Deprecated:” notice before <!DOCTYPE html> confirms the cause. The fix is the same as for the PHP warning about headers, so follow our guide to the headers already sent warning and skip the rest of this page. If the message ends with “not supported by your browser”, continue with step 2.

2. Rule out the browser in one minute. Open a private window, or a second browser, and log in there. A private window starts without stored cookies and usually without extensions.

  • It works in the private window: the problem is local. Remove cookies for your site in the browser settings, and allow cookies for it if a rule blocks them. Then disable privacy or ad-blocking extensions one at a time.
  • It fails in the private window too: the problem is on the server side. Continue with step 3.

A login form shown inside a frame on another site, such as a page builder preview on a different domain, can also fail here. The browser treats that cookie as a third-party one. Open wp-login.php directly in its own tab instead.

3. Compare the address you use with siteurl and home. Run these from the WordPress folder:

cd ~/public_html
wp option get siteurl
wp option get home

Example output:

https://example.com
https://example.com

Now look at the address bar on the login page. If you are on https://www.example.com/wp-login.php but siteurl says https://example.com, the form posts to the host without www. The test cookie belongs to www.example.com only, so the browser never sends it there, and WordPress reports “not supported”. The same happens the other way round.

Without WP-CLI, open phpMyAdmin, select the site’s database and look at the siteurl and home rows in the wp_options table. Your table prefix may differ from wp_.

To get in right now, log in at the exact host shown in siteurl, such as https://example.com/wp-login.php. To stop it happening again, add a permanent (301) redirect from the other host to the siteurl host in your web server configuration or .htaccess, so nobody lands on the wrong host.

4. Look for cookie and HTTPS overrides in wp-config.php. These constants change the cookie from what WordPress would pick on its own:

grep -nE "COOKIE_DOMAIN|COOKIEPATH|SITECOOKIEPATH|WP_HOME|WP_SITEURL|HTTPS" ~/public_html/wp-config.php

Example output:

92:define( 'COOKIE_DOMAIN', 'www.example.com' );
93:define( 'WP_HOME', 'https://example.com' );
94:define( 'WP_SITEURL', 'https://example.com' );

No output means no overrides, so move on to step 5. Otherwise, read each line with these rules:

  • COOKIE_DOMAIN must be the host you log in on, or a parent of it such as .example.com. A value from another site, often copied over with a migration or a staging clone, makes the browser refuse the cookie outright. On a single site, delete the line and let WordPress use its empty default. On a multisite network, fix the value instead of deleting it.
  • COOKIEPATH and SITECOOKIEPATH must be a path that /wp-login.php sits under, which is / for a site installed at the domain root. Delete them unless you know why they are there.
  • WP_HOME and WP_SITEURL override the database values from step 3. When they exist, change the address here, because wp option update cannot win against them.
  • $_SERVER['HTTPS'] = 'on'; without a condition around it tells WordPress every visit is encrypted. A visit over plain http then receives a Secure cookie, which browsers throw away. Wrap it in a check of the X-Forwarded-Proto header your proxy sends, or remove it once the site redirects all traffic to https.

Copy the file before each edit, and change one line at a time:

cp -p ~/public_html/wp-config.php ~/wp-config.php.bak

The copy prints nothing when it succeeds.

5. Read the Set-Cookie header of the login page. This shows what the server really sends:

curl -s -D - -o /dev/null https://www.example.com/wp-login.php | grep -iE "^(set-cookie|cache-control|age|x-cache|cf-cache-status|x-litespeed-cache):"

It works like curl -I, but it sends a normal GET request. Some caches answer the HEAD request that curl -I sends differently from a real page load.

Expected output on a healthy site:

cache-control: no-cache, must-revalidate, max-age=0, no-store, private
set-cookie: wordpress_test_cookie=WP%20Cookie%20check; path=/; secure; HttpOnly

Read the result like this:

  • A set-cookie line with no domain= is the default and is fine.
  • A domain= value that does not match your host is the COOKIE_DOMAIN problem from step 4.
  • No set-cookie line at all, together with cf-cache-status: HIT, x-litespeed-cache: hit, x-cache: HIT or an age: header, means a cache served a stored copy. Go to step 6.

6. Take the login page out of every cache. WordPress sends no-cache headers on wp-login.php, but a CDN rule that forces caching or a page cache plugin can still store it. A stored copy never sends the test cookie. Exclude /wp-login.php and /wp-admin/ in the page cache plugin’s exclusions. On Cloudflare, add a Cache Rule that bypasses the cache when the URI path contains wp-login.php. Then purge the cache and repeat step 5. Our article on cookies through Cloudflare explains why a forced cache strips Set-Cookie.

7. Test security plugins and the WAF. A WAF (web application firewall, a filter that inspects requests before they reach WordPress) or a security plugin can rewrite login requests or drop the Cookie header. Look in the WAF’s event log, such as the ModSecurity log in cPanel or Cloudflare’s Security Events, for requests to /wp-login.php from your IP address. To test a plugin, turn it off for a few minutes:

wp plugin list --status=active --field=name
wp plugin deactivate wordfence

Example output of the second command:

Plugin 'wordfence' deactivated.
Success: Deactivated 1 of 1 plugins.

Replace wordfence with the security plugin you actually run. Without WP-CLI, rename its folder in wp-content/plugins/, for example to wordfence.off. Try to log in. If it works, turn the plugin back on and look for its login protection or cookie settings rather than leaving it off.

Validate it works

This test follows the same path as a browser, with no password. It loads the login page, keeps the cookie in a file, and submits an empty form to the address the form really uses.

First find the form’s target:

curl -s https://www.example.com/wp-login.php | grep -o 'action="[^"]*wp-login.php[^"]*"'

Example output:

action="https://www.example.com/wp-login.php"

Then load the page and post an empty form with the saved cookie. In the second command, use the exact action address from the output above, even when its host differs from the one you loaded. That mismatch is what the browser goes through too.

curl -s -c /tmp/wpjar -o /dev/null https://www.example.com/wp-login.php
curl -s -b /tmp/wpjar -d "log=&pwd=&testcookie=1" https://www.example.com/wp-login.php | grep -o "Cookies are blocked[^.<]*\|The username field is empty"

Expected output when the cookie makes the round trip:

The username field is empty

“The username field is empty” means the test cookie arrived and WordPress moved on to checking the empty username. “Cookies are blocked or not supported by your browser” means it is still lost, so go back to the step whose check matched. On a site whose language is not English, both lines come back translated, so search for your language’s wording instead. The empty username cannot lock any account, though some security plugins may count it as one failed attempt from your IP address. Delete the cookie file afterwards with rm /tmp/wpjar.

Finally, log in through the browser at the siteurl address. You should land on the Dashboard. In the developer tools Network tab, the POST to wp-login.php should list wordpress_test_cookie under its request cookies.

Troubleshooting

The browser drops the cookie and you cannot tell why. Open the developer tools (F12), then the Network tab, and reload wp-login.php. Select the request and open Cookies. Chrome highlights a response cookie it refused and explains the reason when you hover over it. In Firefox, check the Storage tab to see whether the cookie was saved at all.

The message changed to a redirect loop. Once the test cookie works, a login that bounces you back to wp-login.php with no error is a different fault in the login cookies themselves. Our guide to the WordPress login redirect loop covers it.

It fails only for some users. Check whether they use a bookmark with www or with http. The server-side redirect from step 3 fixes this for everyone.

It started right after a migration or a staging clone. Look first at COOKIE_DOMAIN, WP_HOME and WP_SITEURL in wp-config.php. Migration tools copy those lines along with the file.

A custom login form never shows the message. Forms built with wp_login_form() do not send the testcookie field, so WordPress skips the second check. A lost test cookie then shows up differently, often as a return to the login form with no message. Run the same checks from step 2 onward.

When this is the wrong approach

If a Cloudflare challenge keeps looping before you ever see the WordPress form, the edge rule is the problem, not the WordPress cookie. Fix the rule first. If the site itself shows a critical error or a blank page, WordPress never gets as far as the cookie checks. On a multisite network with domain mapping, cookie settings are shared across sites, so change COOKIE_DOMAIN only after checking every mapped domain. The WordPress handbook page on cookies lists every cookie WordPress sets.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.