Troubleshooting · Troubleshooting
How to Fix "Headers Already Sent" in WordPress
Short answer
The “headers already sent” warning means a PHP file sent output to the browser before WordPress could send its headers, so logins, redirects and cookies fail. Read the warning: the file named after “output started at” is the culprit, and the second file is only where WordPress noticed the failure. Open the culprit file, delete any whitespace before the opening <?php tag or after the closing ?> tag, save it as UTF-8 without BOM, and reload the page.
Key takeaways
- The file named after “output started at” holds the fault; the second file in the warning is only where WordPress noticed it.
- A single space, blank line or hidden UTF-8 BOM before the opening <?php tag counts as output and blocks every header after it.
- Save PHP files as plain UTF-8 without BOM, and leave off the closing ?> tag in files that hold only PHP.
- When the warning names a plugin or theme file, deactivate that plugin or switch themes to confirm it is the cause.
- Output buffering with output_buffering = 4096 hides the warning but does not repair the file that sent output early.
- Logins, redirects and cookies fail while the warning is active, so fix the file instead of hiding the message.
What does “headers already sent” mean in WordPress?
It means a PHP file sent output to the browser before WordPress sent its HTTP headers, so WordPress cannot set cookies, redirects or other headers.
HTTP headers are instructions that travel ahead of the page, such as a redirect address or a login cookie. The PHP manual states that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
Once one byte of output leaves, PHP closes the header block, and the manual adds that you cannot add any more header lines with header() after that point.
This warning is about PHP output order, not about security headers. If you want to add security headers to a site, that is a separate job covered in our security headers guide.
Why does this warning appear on a WordPress site?
It appears when a file WordPress loads prints something, even one invisible character, before WordPress sends a header for a login, redirect or cookie.
WordPress runs on PHP, and every page load passes through files such as wp-config.php, theme functions and plugin files. If any of those files sends output early, the first header WordPress tries to send fails and the warning appears.
Logins are the most common place to see it, because logging in needs a cookie and a redirect to the dashboard. A front page can look fine while the same warning breaks the login screen, since the front page may not need to send a header at that point.
The warning is only a warning, so parts of the site keep working while logins and redirects fail. That split is why the warning is easy to miss until a login or redirect fails.
Other PHP warnings can look similar, so check whether you are facing a different fault in our 500 error guide.
How do you read the warning to find the faulty file?
Read the file and line named after “output started at”; that file sent the early output, while the file named at the end is only where WordPress tried to send a header.
Warning: Cannot modify header information - headers already sent by
(output started at /path/blog/wp-config.php:34)
in /path/blog/wp-login.php on line 42
WordPress's own troubleshooting FAQ gives this exact example and states the fault sits at line 34 of wp-config.php, not line 42 of wp-login.php. The login file is the victim: it was hit by the extra whitespace at line 34 of wp-config.php.
The same rule holds when the second file is wp-includes/pluggable.php or wp-admin/post.php. The FAQ shows a second example where line 8 of admin-header.php is the fault and line 569 of post.php is the victim.
Never edit the second file to fix the warning, because the fault sits in the first file.
What causes the warning most often?
Stray whitespace or a hidden byte order mark in a file WordPress loads causes most cases, with faulty plugin or theme code next in line.
WordPress's troubleshooting FAQ states the usual cause is spaces, new lines or other content before an opening <?php tag or after a closing ?> tag, typically in wp-config.php.
| Cause | Where it shows up | First check |
|---|---|---|
Whitespace before <?php | Any PHP file, often wp-config.php | Open the file and look at line 1 |
Whitespace after ?> | Theme or plugin files | Look at the end of the file |
| UTF-8 BOM | Any file saved with BOM | Check the file encoding |
| HTML before a header call | Theme or plugin files | Look for markup above the PHP code |
echo or print before a header | Plugin or theme code | Search for output before the header call |
| Faulty plugin or theme code | wp-content/plugins or wp-content/themes | Deactivate the plugin or switch themes |
Kinsta's guide lists the same causes: whitespace before the opening tag or after the closing tag, an HTML block before the header function, print or echo statements before the header function, and problems with a plugin's code.
The warning also appears when code calls wp_redirect() after content has been sent. WordPress's FAQ suggests a JavaScript redirect instead in that case.
How do you fix stray whitespace in a PHP file?
Open the file named after “output started at”, delete every space and blank line before the opening <?php tag and after the closing ?> tag, then save and reload the page.
Back up the file before you change it, so you can restore it if the edit goes wrong. Our WordPress backup guide walks through the options.
- Download the file with FTP or your host's file manager.
- Open it in a plain text editor such as Notepad, not a word processor.
- Go to the line named in the warning and delete any spaces or blank lines before
<?php. - Go to the end of the file and delete any spaces or blank lines after
?>. - Save the file, upload it back, and reload the page that showed the warning.
WordPress's FAQ gives the same routine: download the file, open it in a plain text editor, check that the very first characters have no blank lines or spaces, and save it as plain UTF-8.
If you can still open the dashboard and the warning names a theme file, you can edit it under Appearance > Theme Editor and click Update File. Kinsta's guide describes this path, and the same editor exists for plugins under Plugins > Plugin Editor.
How do you remove a UTF-8 BOM from a PHP file?
Re-save the file as plain UTF-8 without BOM in your editor, because the BOM is an invisible marker at the start of the file that PHP sends as output.
A BOM is a byte order mark, a hidden marker some editors add at the start of a file to mark its encoding. WordPress's FAQ states that if the file is encoded as UTF-8 with BOM, the BOM is seen as a character which starts the output.
Because the mark sits at the very start of the file, a BOM can trigger the warning even when the file looks clean in your editor. WordPress's FAQ puts it plainly: just because you cannot see anything does not mean that PHP sees the same.
In most editors, choose the save option labelled UTF-8 without BOM, or plain UTF-8. WordPress's FAQ warns to use plain UTF-8 or any encoding without the BOM suffix.
How do you find a faulty plugin or theme?
Deactivate your plugins one at a time and reload the page after each one until the warning stops, which points to the plugin you just turned off.
WordPress's FAQ recommends disabling plugins one at a time until you find the source, and notes the cause is often two or more plugins trying to use the same resources.
If the warning names a plugin file, reinstalling that plugin often clears it, because a fresh copy replaces the damaged file. Kinsta's guide notes you may lose that plugin's settings, so note them down first.
For a theme file, switch to a default WordPress theme and reload the page. If the warning goes away, the fault sits in your theme's code.
When you edit plugin or theme files, leave off the closing ?> tag at the end of files that hold only PHP. WordPress's coding standards state that omitting the closing tag is preferred, and that you must remove trailing whitespace if you keep the tag.
How do you fix the error when you cannot open the dashboard?
Use FTP or your host's file manager to open the faulty file, because the warning may block the login screen and the dashboard editors with it.
Kinsta's guide describes the FTP path: connect with your FTP or SFTP client, open the root folder, which is often named public_html, public or root, and edit the file named in the warning.
If you cannot reach the dashboard at all, you can turn off every plugin from the database. WordPress's FAQ explains the phpMyAdmin route: in the wp_options table, find the active_plugins row and set its option_value field to a:0:{}.
You can also rename the plugins folder through FTP, which turns off every plugin but keeps their settings. WordPress's FAQ notes this method preserves plugin options, though each plugin needs manual reactivation after.
If the faulty file is wp-config.php and you have no backup, replace it with a fresh copy from a WordPress download and re-enter your database details.
When is output buffering a safe temporary fix?
Output buffering is a short-term patch when you cannot edit the faulty file right away, because it holds output in memory until PHP has sent the headers.
DreamHost's knowledge base gives the easy route on its hosting: add output_buffering = 4096 to your user's phprc file. The same article calls editing the code so header() runs before any output the advanced fix.
Treat buffering as a patch, not a repair. The faulty file still sends output early, and the next edit to that file can bring the warning back.
If you use buffering, set a reminder to fix the file itself, because the warning can return after a plugin update or a move to a new host.
How do you check that the fix worked?
Reload the page that showed the warning and then log in: if the warning is gone and the login sends you to the dashboard, the fix worked.
- Reload the page that showed the warning and confirm the message is gone.
- Log out and log back in to check the login cookie and redirect work.
- Open a post edit screen, since that page also sends headers for the admin area.
- Save a post or a setting to confirm forms that redirect still work.
If the warning still shows, read it again: the file and line may have changed, which means you fixed one fault and another file still sends output early. Repeat the same checks on the new file named in the message.
Turn on the debug log if the warning only appears sometimes. WordPress's debugging handbook shows the three lines to add above the “That's all, stop editing!” line in wp-config.php: WP_DEBUG true, WP_DEBUG_LOG true and WP_DEBUG_DISPLAY false.
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
With those lines set, WordPress writes errors to wp-content/debug.log instead of showing them on screen. The handbook states the log saves to debug.log in the content directory, usually wp-content/debug.log.
Switch the debug lines back off when you finish, since the handbook states these tools are meant for local testing and staging installs, not live sites.
If the warning returned right after a PHP change, walk through how to update PHP for WordPress to check the version change was done cleanly.
When should you contact your host?
Contact your host when the warning names a file you cannot reach, when the fault returns after every fix, or when you cannot edit files through FTP or the file manager.
Your host can check the server's PHP setup, file permissions and error logs, which you cannot see from the dashboard.
Also contact your host if the warning appeared right after a server change, such as a PHP version change or a move to a new server. Only the host can confirm what changed on the server side.
Send the host the full warning text, including both file paths and line numbers. That text tells them exactly which file sent output first.
What mistakes should you avoid?
Do not hide the warning and move on, do not edit the second file named in the message, and do not leave the closing PHP tag in files that hold only PHP.
- Hiding the warning with WP_DEBUG_DISPLAY false leaves logins, redirects and cookies broken.
- Editing wp-includes/pluggable.php or wp-login.php wastes time, since the fault is in the first file.
- Saving a PHP file as UTF-8 with BOM adds the hidden marker back.
- Editing wp-config.php in a word processor can add hidden characters; use a plain text editor.
- Leaving debug mode on after the fix can show errors to visitors, so switch it off.
WordPress's debugging handbook states it is not recommended to use WP_DEBUG or the other debug tools on live sites, since they are meant for local testing and staging installs.
Keep one PHP block per file where the FAQ advises it, and do not split code into extra blocks with blank lines between them. WordPress's FAQ warns against putting code in unnecessary code blocks.
Frequently asked questions
Why does the warning point at wp-login.php or pluggable.php?
Those files are where WordPress tried to send a header and failed, not where the fault sits. The real culprit is the file named after “output started at” in the warning. Fix that file and leave the core files alone, since they are replaced on the next WordPress update anyway.
Can I just hide the warning with WP_DEBUG_DISPLAY?
No. Setting WP_DEBUG_DISPLAY to false only stops the message from showing on screen. The early output still blocks headers, so logins, redirects and cookies keep failing. Use WP_DEBUG_LOG instead to record the error in wp-content/debug.log while you fix the file that sent output early.
Does this error mean my site was hacked?
Almost never. The warning usually comes from an editing slip, such as a space before the opening PHP tag, a hidden BOM, or a faulty plugin update. If the warning names a file you never edited, check which plugin or theme was updated most recently, since that update is the likely source.
Why does the warning appear only on the login page?
Logging in needs a cookie and a redirect to the dashboard, and both need headers. A front page often needs no header at that point, so it can look fine while the login screen fails. The fault is the same either way: some file sent output before WordPress could send its headers.
Will reinstalling WordPress fix the warning?
Only if the faulty file is a WordPress core file. Reinstalling does not touch wp-config.php, your theme files or your plugins, so the warning will stay if the fault sits in one of those. Restore the faulty file from a backup first, or replace the plugin or theme the warning names.
What if the warning names a file I never edited?
A plugin or theme update may have added the stray output, or another person with file access may have edited it. Deactivate the plugin or switch themes to confirm the source, then reinstall the plugin or theme from a fresh copy to replace the damaged file.
Sources
- FAQ Troubleshooting – Advanced Administration Handbook Developer.WordPress.org
- PHP: header - Manual PHP.net
- PHP Coding Standards Developer.WordPress.org
- Debugging in WordPress Developer.WordPress.org
- How to Fix the "Cannot Modify Header Information - Headers Already Sent By" Error Kinsta
- Cannot modify header information DreamHost Knowledge Base
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.
Thanks — we review requests within 3 business days.
