Call Us Toll Free - US & Canada : 888-818-9916 UK : 800-069-8778 AU : 1800-990-217
Cookies Are Blocked Due to Unexpected Output

How to Fix ‘Cookies Are Blocked Due to Unexpected Output’ Error in WordPress

Spread the love

Introduction

The most widely used website platform worldwide is WordPress. Online stores, blogs, and businesses are all powered by it. However, it may encounter issues like any other software. This is one of the typical errors that appears during login:

“ERROR: Cookies are blocked due to unexpected output.”

This error usually appears on the wp-login.php page. It stops you from logging into your WordPress admin area. It can be frustrating, especially if you’re not sure why it’s happening.

The message means that WordPress tried to set a cookie, but something went wrong. That “something” is usually unexpected output sent before headers. This breaks the cookie-setting process, which depends on clean HTTP headers.

Here’s what typically causes the error:

  • Extra spaces or blank lines in wp-config.php
  • Plugins or themes sending output before they should
  • BOM (Byte Order Mark) added by text editors
  • PHP errors or debug messages printed early

Many users panic when they see this message. But the good news is — it’s fixable. By taking a few easy actions, you can fix this mistake even if you don’t have extensive technical knowledge.

What Causes the “Cookies Are Blocked Due to Unexpected Output” Error?

There is a pattern to the “Cookies are blocked due to unexpected output” problem. It appears because something has gone wrong before WordPress could send headers. When this happens, cookies cannot be set correctly, and login fails. Let’s examine the most frequent causes of this mistake.

  1. Extra Whitespace in wp-config.php or Other Files

The most frequent source of this problem is whitespace. If there is a blank line before the opening <?php or after the closing ?> in the wp-config.php file, it may cause trouble. WordPress tries to send headers before it shows any content. If anything appears early — even a space or empty line — headers fail.

Check for:

  • Blank lines at the start or end of wp-config.php
  • Extra spaces in functions.php, index.php, or wp-settings.php

Even a small space can break the login process.

  1. Plugins Sending Output Too Early

Some plugins can trigger output before WordPress is ready. This can happen if a plugin has echo statements, debug prints, or HTML outside of functions. These outputs send data to the browser before headers, which blocks cookies from being set.

Early output may come from:

  • Poorly coded plugins
  • Plugins incompatible with the version of WordPress you are using
  • Plugins that throw PHP warnings or notices

This is why plugin conflicts are a frequent issue.

  1. Themes That Cause Header Conflicts

Just like plugins, themes can also send output too early. If your active theme has print statements, or direct output in functions.php, it can trigger this error.

The following are common causes of header problems from themes:

  • Custom-coded themes with unclean structure
  • Old themes not updated for recent WordPress versions
  • Theme files edited incorrectly

To find out if your theme is the problem, try switching to the default theme.

  1. BOM (Byte Order Mark) in Files

The BOM is an invisible character saved at the beginning of a file. It often appears when you edit files using programs like Notepad. It sends the output before the headers if it is present.

WordPress doesn’t need BOM, and it causes problems like:

  • Cookie setting failure
  • “Headers already sent” warnings
  • Site crash or login block

Use a proper code editor like Notepad++ or VS Code to avoid this.

  1. PHP Warnings or Debug Output

PHP warnings, notices, or error messages printed before the headers can trigger this error. Even harmless debug messages can stop cookies from working.

Check your site’s debug logs or enable WordPress debug mode to find these outputs.

All these causes interfere with the normal login process. Now that you understand the possible reasons.

How to Fix the “Cookies Are Blocked Due to Unexpected Output” Error?

Don’t worry if the message “Cookies are blocked due to unexpected output” appears. The problem may look technical, but it’s fixable. Below are six proven ways to solve this issue. Follow each step carefully and check your site after every fix.

  1. Remove Extra Whitespace in wp-config.php and Other Files

Whitespace refers to extra spaces or blank lines in code files. These may seem harmless but can break your WordPress login.

This is the most common reason for the WordPress cookies blocked unexpected output error. Even one space outside PHP tags can prevent cookies from being set.

Why it matters:

WordPress needs to send headers before any output. If there is extra space before or after PHP code, headers are sent too early. It results in a cookie error.

Steps to fix:

  1. Log in to your hosting account.
  2. Open the File Manager or use an FTP client, such as FileZilla.
  3. Go to your WordPress website’s root folder.
  4. Locate and open the wp-config.php file.
  5. Ensure the file starts with <?php — with no blank line before it.
  6. Also check the end — there should be no closing ?> or extra spaces after code.
  7. Repeat the same for other core files:
    • functions.php (in your theme folder)
    • index.php
    • wp-settings.php

After saving the changes, try logging in again. If the error is gone, you’ve fixed it.

  1. Add ob_start() to wp-config.php

PHP’s output buffering is activated via the ob_start() function. This means output is held until the script finishes processing.

This method can solve the WordPress login cookie blocked unexpected output issue by preventing headers from being sent too early.

Why it works:

If some plugin or file sends output too soon, ob_start() holds that output. It gives WordPress time to set cookies properly.

Steps to fix:

  1. Go to your wp-config.php file.
  2. Open it in a code editor or your cPanel File Manager.
  3. At the top of the file, just after <?php, add this line:

ob_start();

  1. Save the file and reload your login page.

This function doesn’t fix the root cause but acts like a band-aid. It’s useful when you need quick access and can’t find the exact issue yet.

  1. Remove BOM (Byte Order Mark) from PHP Files

BOM stands for Byte Order Mark. It is an invisible character that appears at the start of some text files. It can cause PHP to send headers too early.

This is a known trigger for the plugins sending output before headers WordPress cookies error.

Why it matters:

BOM may not be visible but still counts as output. That’s why headers fail, and cookies break.

How to check and fix BOM:

  1. Download a code editor like Notepad++ or Visual Studio Code.
  2. Open your wp-config.php file in the editor.
  3. In Notepad++, go to Encoding in the top menu.
  4. If you see “Encode in UTF-8-BOM”, change it to “Encode in UTF-8”.
  5. Reupload the file to your server after saving it.
  6. Do the same for functions.php and other recently edited PHP files.

After cleaning the BOM, reload your site and try logging in.

  1. Disable All Plugins via FTP or File Manager

Faulty or outdated plugins often send output at the wrong time. This breaks the login process and causes cookie errors.

Why this step works:

Some plugins echo content or print debug info. These actions send headers before WordPress is ready. Disabling all plugins helps identify the bad one.

How to do it:

  1. Go to your hosting dashboard.
  2. Open File Manager or connect via FTP.
  3. Go to wp-content/plugins.
  4. The entire plugins folder should be renamed to something like plugins-old.

This will deactivate all plugins.

  1. Try accessing your WordPress admin account.

If you can log in now, one of your plugins is the problem.

  1. The folder should be renamed to plugins.
  2. Next, go to your dashboard and reactivate each plugin individually.
  3. Refresh after each activation to see which one breaks the login again.
  4. Switch to a Default WordPress Theme

Themes can also cause the WordPress cookies blocked unexpected output error. If the theme sends output too early, cookies will not work.

When this helps:

If your website uses a custom theme or one that has been manually altered, this is helpful.

How to switch:

  1. Go to your hosting File Manager or FTP.
  2. Navigate to wp-content/themes.
  3. Rename your active theme folder to something else (e.g., mytheme-old).
  4. If WordPress is installed, it will automatically change to a default theme, such as Twenty Twenty-One.

If the login is now successful, the problem is with your theme.

Tip: Check functions.php in your theme. Look for any echo, print, or space outside PHP tags.

  1. Enable Debugging in WordPress

Debugging helps find out where the output is coming from. It shows warnings, notices, or other outputs that may cause the cookie error.

Why use this:

It gives more detail on which plugin, theme, or file is causing problems.

Steps to enable debugging:

  1. Go to the wp-config.php file.
  2. Add the following lines before the line that says /* That’s all, stop editing! */:
  • define( ‘WP_DEBUG’, true );
  • define( ‘WP_DEBUG_LOG’, true );
  • define( ‘WP_DEBUG_DISPLAY’, false );
  1. Save the file and reload your site.
  2. WordPress will now create a debug log file in /wp-content/debug.log.

Check this file to see what errors are showing before the headers are sent.

If the log mentions a specific plugin or theme file, that’s your starting point.

Final Tip

After trying each fix, test your login page again. There’s no reason to keep trying if one approach works. Otherwise, proceed to the following step.

Before you make any changes, make a backup of your files. Always edit files using trusted code editors to avoid BOM or formatting issues.

Preventing Future Cookie Errors

Once you fix the cookie error, it’s smart to prevent it from happening again. Most of the time, this issue comes back after updates or file edits. Here are some pointers for maintaining the cleanliness and functionality of your website.

  1. Always Use a Proper Code Editor

Avoid editing PHP files in basic text editors like Notepad or WordPad. These editors often add invisible characters like BOM (Byte Order Mark), which cause cookie issues.

Instead, use editors like:

  • Visual Studio Code
  • Sublime Text
  • Notepad++

These tools support UTF-8 encoding and won’t add unwanted characters.

  1. Don’t Add or Leave Extra Spaces

Always check your files for extra spaces or blank lines. A single space before <?php or after closing tags can break headers.

Tips to avoid whitespace errors:

  • Never leave a blank line at the start of PHP files.
  • Avoid adding a ?> tag at the end of files.
  • Delete trailing spaces after code.
  1. Keep Plugins and Themes Updated

Output issues might be caused by outdated or badly developed plugins and themes. Bugs that affect cookies or headers are frequently fixed by these upgrades.

Set reminders to check for updates regularly. Also, remove plugins you don’t use. Fewer plugins mean fewer chances for conflicts.

  1. Use a Staging Site for Testing

Never make direct changes on your live site. Changes should always be tested first in a staging environment. One-click staging tools are available from many hosting companies.

This helps avoid breaking your live login and keeps visitors unaffected.

  1. Backup Before Editing Core Files

If you must edit wp-config.php or theme files, make a backup first. Use your host’s backup tools or download files manually via FTP.

If something goes wrong, you can quickly restore the website using this method.

These small steps can help you avoid seeing the WordPress cookies blocked unexpected output error again.

Conclusion

It’s critical to resolve the “Cookies are blocked due to unexpected output” error. It keeps your WordPress login safe and your admin access smooth. A minor error in a file can cause your website to crash. That’s why it’s smart to act fast and fix the issue properly.

Don’t worry if the issue persists or if you’re unclear on what to do. You don’t need to handle it alone.

The expert team at 24x7wpsupport.com is here to help. We fix cookie errors, plugin issues, and theme bugs — all day, every day.

  • Quick fixes
  • Safe hands
  • Expert WordPress support

Get your site back online — contact us now!

Visit 24x7wpsupport.com

Category:

Share:

Join the discussionSHARE YOUR THOUGHTS

×

DO YOU NEED HELP?

24x7wpsupport
Join the Course

Top 7 WooCommerce SEO Plugins for 2023 to Boost Your Google Ranking