More fixes

"Cannot modify header information - headers already sent" in WordPress

The page shows a warning like "Cannot modify header information - headers already sent by (output started at /wp-content/themes/yours/functions.php:42)", and often the login or a redirect stops working with it. Before WordPress can send a redirect or a login cookie, nothing may have been printed to the page. Some file printed something first: usually a blank line, a space or an invisible byte-order mark before <?php or after a closing ?>. The message tells you exactly where: the part in brackets after "output started at" is the file and line to fix, not the file the warning is "in".

What the owner sees

harborbakery.example/wp-login.php

What the checks found


  

Find out which case it is (five minutes)

  1. Read the brackets. Copy the path after "output started at". That file and line number printed too early. The file named before it (often pluggable.php or wp-login.php) is only where WordPress noticed, and is almost never the one to change.
  2. Did you just edit a file? A recent edit to functions.php or wp-config.php, or a snippet pasted from a website, is the usual source. A space or empty line before the first <?php, or after a final ?>, is enough.
  3. Does it name a plugin folder? A path under wp-content/plugins/ means that plugin printed something early, often right after an update. Its name is the folder after plugins/.
  4. Is the line a warning itself? If the line shown printed a PHP notice or deprecation message (see PHP warnings on the site), that printed text is what broke the headers. Fix or hide the first warning and this one goes with it.

The fixes, by case

  1. Take a copy of the file first (download it with the host's File Manager or FTP). You are about to remove a few characters, and a copy makes that reversible.
  2. Stray space or blank line: open the file named in the brackets in the host's File Manager editor, go to the very top, and make sure <?php is the first thing in the file, with nothing before it. At the very end, delete a closing ?> and any blank lines after it; WordPress files do not need one.
  3. Invisible byte-order mark: if the top looks clean, the file was saved with a "BOM" by a desktop editor. Re-save it as "UTF-8 without BOM" (Notepad++: Encoding, UTF-8; VS Code: click "UTF-8 with BOM" in the status bar, Save with Encoding, UTF-8) and upload it again.
  4. A plugin is printing early: rename its folder in wp-content/plugins/ (add -off), check the site works, then update or replace that plugin before turning it back on.
  5. A PHP warning is printing: on a live site, warnings should go to a log, not the page. In wp-config.php set define('WP_DEBUG_DISPLAY', false); and fix the warning itself when you can.
  6. Log in and check again: clear the browser cache, log in, save a post. No warning at the top and a working redirect means it is fixed.

What you see, what it means, what it needs

What you seeWhat it meansUsual fix
"output started at .../functions.php:1"Something before <?php: a space or a byte-order markDelete it, or re-save as UTF-8 without BOM
"output started at" the last line of a fileBlank lines after a closing ?>Delete the closing tag and what follows
"output started at .../wp-config.php"A pasted line in the config printed textRemove the stray characters at the top or bottom
Path under wp-content/plugins/name/That plugin prints before WordPress is readyTurn it off by renaming its folder, then update or replace it
Starts after a PHP upgrade, with "Deprecated" lines aboveOld code prints warnings on the new PHPHide warnings on screen, update the code that warns

What not to do

Most of these are one space, one closing tag or one re-save. If the brackets name a file you cannot find or a plugin you need, that is what the box below is for. Related: PHP warnings on the site, login keeps going back to the login page and blank white screen.