You log in to WordPress and land back on wp-login.php, and the top of the page shows “Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/wp-config.php:1)”. The same warning can break redirects after saving a form, empty your RSS feed, or stop the block editor from saving. PHP prints it when a file sends page content before WordPress has finished sending its headers. The fix is to open the file named after “output started at”, go to that line, and remove the stray output. It is usually an invisible byte order mark, a blank line, or a leftover debug echo.
What you’ll accomplish
- Read the warning and tell the file that caused it apart from the file that only reported it.
- Check the first and last bytes of that file with
xxdand see exactly what it sent. - Remove a byte order mark, a trailing blank line or debug output without breaking the file.
- Stop PHP notices from printing into pages, which is the usual cause right after a PHP upgrade.
- Confirm with
curlthat the login redirect and the feed are clean again.
Prerequisites
You need SSH or cPanel Terminal access as the account user, and a backup of any file before you edit it. WP-CLI (the wp command) helps in two steps, and each of those steps gives a manual alternative.
The commands assume a Linux server with GNU tools, which is what cPanel servers on AlmaLinux, Rocky Linux or CloudLinux ship. The sed command in step 5 behaves differently on macOS, so run it on the server rather than on your laptop. The wording of the warning is the same on PHP 7.4 and every PHP 8 release.
How it works
An HTTP response has two parts. The headers come first and carry things like the redirect target (Location) and the login cookie (Set-Cookie). The body comes after them and holds the page itself. Once PHP sends the first byte of body, the headers are gone, and any later call to header(), setcookie() or session_start() fails with this warning.
The message always names two files, and they play opposite roles:
- “output started at FILE:LINE” is the culprit. That file and line sent the first byte of body. This is the one you fix.
- “in FILE on line N” is the victim. It is usually a WordPress core file such as
wp-includes/pluggable.php, wherewp_redirect()and the login cookie code live. It did nothing wrong, so leave it alone. Its line number changes between WordPress versions.
Output buffering decides whether you see it at all. Output buffering means PHP holds the start of the body in memory and sends the headers first. The output_buffering setting controls it. The php.ini-production and php.ini-development templates that ship with PHP set it to 4096 bytes. With no php.ini at all, the built-in default is 0, which means off, and command-line PHP forces it to 0 too. So a 3-byte stray mark can sit unnoticed on one server for years, then break logins after a move to a host or PHP build with buffering off.
Buffering hides the warning but not the bytes. The stray output still goes out at the top of every response, even on a server with buffering on. Browsers and feed readers then reject the feed with an error such as “XML declaration allowed only at the start of the document”. The block editor reports “The response is not a valid JSON response” when you save.
Step-by-step
1. Get the full warning text. If it shows on screen, copy all of it. If not, search the PHP error logs. On cPanel, PHP writes an error_log file in the folder of the script that ran, and WordPress writes wp-content/debug.log when its own logging is on.
grep -h "headers already sent" ~/public_html/error_log ~/public_html/wp-admin/error_log ~/public_html/wp-content/debug.log 2>/dev/null | tail -n 3
Example output:
[29-Sep-2026 13:07:52 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/wp-config.php:1) in /home/user/public_html/wp-includes/pluggable.php on line 1450
Write down the path and line after “output started at”. No output means the warning was never logged, so reproduce it once in the browser and run the command again. Our guide to reading WordPress error logs covers where each log lives.
2. Look at what is in front of <?php. When the culprit line is 1, the first bytes of the file are almost always the problem.
head -c 16 ~/public_html/wp-config.php | xxd
Example output from a file with a byte order mark:
00000000: efbb bf3c 3f70 6870 0a2f 2a2a 0a20 2a20 ...<?php./**. *
A byte order mark (BOM) is three invisible bytes, ef bb bf, that some editors add to the start of UTF-8 files. Windows Notepad added one every time it saved as UTF-8 until 2019, and many editors still offer “UTF-8 with BOM” as a save option. PHP treats those bytes as page content. A healthy file starts with 3c3f 7068 70, which is <?php. If you see 20 (a space), 0a (a line feed) or 0d0a (a Windows line ending) before 3c3f, the cause is whitespace instead, and step 5 applies the same way.
3. Look at the end of the file when the line is not 1. A line number at or near the end of the file points at text after a closing ?> tag.
tail -c 20 ~/public_html/wp-content/themes/mytheme/functions.php | xxd
Example output:
00000000: 725f 6d65 6e75 7327 2029 3b0a 7d0a 0a3f r_menus' );.}..?
00000010: 3e0a 0a0a >...
The file ends with ?> (3f 3e) and three line feeds (0a). PHP swallows one line feed right after ?>. Anything beyond that, here two extra 0a bytes, is sent to the browser. The line number in the warning then points just past the ?>, often the last line of the file.
4. Look at the exact line for debug output. When the line sits in the middle of a theme or plugin file, print that area with line numbers.
nl -ba ~/public_html/wp-content/themes/mytheme/functions.php | sed -n '40,46p'
Example output:
40 add_action( 'init', 'mytheme_setup' );
41
42 function mytheme_setup() {
43 var_dump( $_SERVER['REQUEST_URI'] );
44 register_nav_menus( array( 'primary' => 'Primary' ) );
45 }
46
A leftover echo, print, print_r() or var_dump() is the culprit here. Delete that line, or wrap it in a check so it never runs on live pages. If the culprit is a file in a plugin you did not write, update the plugin first, since the vendor may have fixed it already.
5. Remove the BOM or stray whitespace. Copy the file, then strip the three BOM bytes from line 1 with GNU sed.
cp -p ~/public_html/wp-config.php ~/wp-config.php.bak
sed -i '1s/^\xEF\xBB\xBF//' ~/public_html/wp-config.php
head -c 5 ~/public_html/wp-config.php | xxd
Expected output:
00000000: 3c3f 7068 70 <?php
For blank lines or spaces before <?php, open the file in the cPanel File Manager editor and delete everything above the tag. For text after a final ?>, delete the ?> itself along with the blank lines. PHP does not need a closing tag at the end of a file, and the WordPress coding standards recommend leaving it out for exactly this reason. Then check that the file still parses:
php -l ~/public_html/wp-config.php
Expected output: No syntax errors detected in /home/user/public_html/wp-config.php. This check does not detect a BOM, so it only confirms your edit did not break the code.
6. Look for other files with a BOM. Editors that add a BOM usually add it to every file they save. This command lists PHP files that contain the three bytes at the start of a line.
LC_ALL=C grep -rlI --include='*.php' $'^\xEF\xBB\xBF' ~/public_html/wp-content/ ~/public_html/wp-config.php
Example output:
/home/user/public_html/wp-content/themes/mytheme/functions.php
/home/user/public_html/wp-content/mu-plugins/site-tweaks.php
The $'...' quoting needs bash or zsh, and cPanel’s Terminal runs bash. The ^ also matches the start of later lines, so confirm each hit with step 2 before you edit it. Fix only files under your control. For a plugin’s file, update or reinstall the plugin instead.
7. Stop notices from printing into pages. Sometimes the culprit is a PHP message, such as “Deprecated: …” or “Warning: Undefined array key”. It appears above the headers warning on screen, and the culprit path points at the plugin that caused it. This is the usual pattern right after a PHP upgrade. The page breaks because the message is printed into it, not because the plugin stopped working. Check how WordPress debugging is set:
wp config get WP_DEBUG
If it prints 1, WordPress is showing every notice. Keep the logging and turn off the display:
wp config set WP_DEBUG_DISPLAY false --raw
wp config set WP_DEBUG_LOG true --raw
Expected output, one line per command:
Success: Updated the constant 'WP_DEBUG_DISPLAY' in the 'wp-config.php' file with the raw value 'false'.
Success: Added the constant 'WP_DEBUG_LOG' to the 'wp-config.php' file with the raw value 'true'.
WP-CLI says “Updated” when the constant was already in the file and “Added” when it wrote a new line. Without WP-CLI, add define( 'WP_DEBUG_DISPLAY', false ); above the “stop editing” line in wp-config.php.
If it prints nothing, or an error saying the constant is not defined, debugging is off. In that case WordPress ignores WP_DEBUG_DISPLAY, and the PHP setting decides. In cPanel, open MultiPHP INI Editor, choose the domain in Basic Mode, and set display_errors to Disabled. Then fix the notice itself by updating the plugin named in the log. Our article on PHP error reporting in production covers the full logging setup.
Validate it works
First, check that the admin redirect sends a real Location header. Replace example.com with your domain.
curl -sI https://example.com/wp-admin/ | grep -iE '^(HTTP|location)'
Expected output:
HTTP/2 302
location: https://example.com/wp-login.php?redirect_to=https%3A%2F%2Fexample.com%2Fwp-admin%2F&reauth=1
A 200 with no location line means the redirect still fails. Next, check that the feed starts with the XML declaration and nothing before it:
curl -s https://example.com/feed/ | head -c 5 | xxd
Expected output:
00000000: 3c3f 786d 6c <?xml
An efbb bf or 0a at the start means another file still sends output. Finally, log in through the browser and run step 1 again. No new log lines with today’s time means the fix held.
Troubleshooting
The culprit is a core file such as wp-includes/functions.php. WordPress core prints deprecation and “doing it wrong” notices from there on behalf of plugins and themes. Read the notice printed just above the warning. It names the function or plugin at fault, and step 7 applies. If you suspect core itself was edited, run wp core verify-checksums. A clean install answers Success: WordPress installation verifies against checksums.
You fixed the file and the warning is still there. A page cache or CDN may still serve the old broken response, so purge it. OPcache, the PHP code cache, rechecks files every 2 seconds by default. On a server where opcache.validate_timestamps is off, ask for PHP-FPM to be restarted.
The BOM came back after the next upload. Your editor is still saving with a BOM. In Notepad++ choose Encoding → Convert to UTF-8, not “Convert to UTF-8-BOM”, then save. In VS Code, click the encoding in the status bar and pick Save with Encoding → UTF-8.
The message is about sessions instead. A plugin that calls session_start() logs “Session cannot be started after headers have already been sent”. The cause and the fix are the same. That message has no “output started at” part, so look for a headers warning from the same minute in the log, or check wp-config.php with step 2.
The login page says “Cookies are blocked due to unexpected output.” WordPress shows this when headers were already sent before the login cookie. It is the same problem, so run steps 1 to 6.
When this is the wrong approach
Turning output buffering on to make the warning vanish is a stopgap, not a fix. You can set output_buffering to 4096 in the MultiPHP INI Editor under Editor Mode to get logins working while you track down the file. The stray bytes will still reach feeds, JSON (the data format the editor and REST API use) and file downloads. If a page ever prints more than 4 KB before WordPress sends its headers, the warning comes back. Remove the setting once the culprit is gone.
If you see a white page or “There has been a critical error on this website” instead, a fatal error is stopping PHP, which is a different problem. Our guide to the WordPress critical error covers it. PHP documents the rule behind this warning on its header() manual page.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.