Headers already sent error-diagnosis and fix
Fix "headers already sent" PHP error. Remove whitespace, BOM, or redirect code before output.
The "Headers already sent" error means PHP tried to send HTTP headers after output was already sent to the browser. Headers must be sent before any output (HTML, whitespace, or text).
UTF-8 BOM is the most common cause
Many text editors (especially on Windows) save PHP files with a UTF-8 BOM (Byte Order Mark). The BOM is invisible but counts as output, causing the error.
To fix:
- Open the affected file in your editor (usually wp-config.php, functions.php, or a custom plugin)
- If using VS Code: File → Save with Encoding → UTF-8 without BOM
- If using Notepad++: Encoding → Encode in UTF-8 without BOM
- Save and reload your site
Extra whitespace before or after PHP tags
If a PHP file has whitespace, blank lines, or HTML after ?>, it will cause this error:
<?php
function my_function() {
// code
}
?>
<!-- This blank line is output! Remove it -->
Fix: Remove any content after the final ?>. It's actually best practice to omit the closing ?> tag entirely in files that are pure PHP:
<?php
function my_function() {
// code
}
// No closing ?> tag needed
Checklist to fix headers already sent
- Open the file mentioned in the error message
- Save it as UTF-8 without BOM
- Remove any whitespace before <?php or after ?>
- Check for any HTML outside of PHP comments
- Check for any echo, print, or output before header() or session_start()
- Reload your site and test
The error message includes the filename and line number where the output occurred. Start debugging there.
Related: Parse errors | Output whitespace issues
Still troubleshooting?
Use UnderHost tools for quick checks, or open a support ticket when the issue needs account or server access.





















