Home/Blog/How to Fix “Headers Already Sent” Warning in WordPress

How to Fix “Headers Already Sent” Warning in WordPress

Headers already sent warning fix guide

You edited functions.php or wp-config.php, and now your site (or just wp-admin) shows: Warning: Cannot modify header information โ€” headers already sent by (output started at /path/to/file.php:12). It looks scary, but the headers already sent warning fix is usually one invisible character. This guide explains what “headers already sent” means, how to read the error to find the offending file, and five ways to fix it.

What Causes “Headers Already Sent”

PHP sends HTTP headers (for redirects, cookies, sessions) before any page content. If anything โ€” even a single space or blank line โ€” is output before those headers, PHP can’t send them and throws this warning. The error message is actually helpful: “output started at …/file.php:12” tells you the exact file and line where the premature output began. Common causes:

  • Whitespace before <?php: a space, tab, or blank line before the opening PHP tag in functions.php, wp-config.php, or a plugin file โ€” the single most common cause.
  • Whitespace or content after ?>: trailing blank lines after the closing PHP tag. Pure-PHP files don’t need a closing tag at all โ€” WordPress recommends omitting it.
  • UTF-8 BOM encoding: some editors save files with an invisible Byte Order Mark at the start, which counts as output. Always save as UTF-8 without BOM.
  • echo/print/var_dump before header() calls: leftover debugging output, or HTML accidentally placed before PHP in a file that later calls header(), setcookie(), or wp_redirect().
  • PHP errors displayed as output: a notice or warning printed before headers counts as output โ€” fixing the underlying PHP issue clears this too.
  • Poorly coded plugin or theme: some plugins echo debug info or HTML during activation hooks, sending output before pluggable.php sets session headers (this is why it sometimes appears only in wp-admin). More coding guides live on the KamiWeb blog.

How to Fix “Headers Already Sent”

Always focus on the first file and line in the message (“output started at”), not the file that tried to send the headers. Open that file via FTP or your hosting File Manager and work through these fixes. Our free web tools can help you verify your site afterward.

Code editor showing invisible whitespace characters concept

  1. Remove whitespace before <?php. Open the file named in the error and delete any spaces, tabs, or blank lines before the opening <?php tag. The file must start immediately with <?php โ€” nothing before it, not even an empty line.
  2. Delete the closing ?> tag. If the file is pure PHP (functions.php, wp-config.php, plugin files), remove the closing ?> at the end entirely โ€” along with any trailing whitespace after it. This is the official WordPress recommendation and eliminates a whole class of these errors.
  3. Save as UTF-8 without BOM. Open the file in a proper code editor (VS Code, Notepad++), check the encoding status bar, and re-save as UTF-8 without BOM. In VS Code, enable View โ†’ Render Whitespace to spot invisible characters. Then re-upload the file.
  4. Remove early output: echo, HTML, and PHP errors. Delete any echo, print, or var_dump statements (especially forgotten debug code) that run before header-related functions, and move header(), setcookie(), or session_start() calls above any output. Also fix any underlying PHP notices/warnings โ€” error messages displayed before headers count as output too.
  5. Isolate the plugin or theme. If the file belongs to a plugin, deactivate it (or reinstall it from a fresh download โ€” the file may simply be corrupt). If it’s the theme’s functions.php, temporarily switch to a default theme to confirm, then fix or replace the theme. As a last resort, ob_start() at the top of wp-config.php enables output buffering โ€” a workaround that captures early output, not a true fix. Browse KamiWeb’s plugin resources for reliable alternatives.

Conclusion

The headers already sent warning fix is almost always invisible: a stray space before <?php, a trailing blank line after ?>, or a hidden BOM character. Read the “output started at” path, open that exact file, clean it up, and the warning disappears. Save PHP files as UTF-8 without BOM and skip closing tags, and it won’t come back. More fixes at KamiWeb.