You refresh your site and see: “Warning: Cannot modify header information – headers already sent by…” followed by a file path. This is a classic PHP error that happens when your server tries to send an HTTP header (like a cookie or a redirect) after it has already started sending the page content. At CODE TOT, we’ve seen this triggered by everything from a single extra space to a hidden “BOM” character.
Professional Insight: 99% of the time, this is caused by “whitespace” before the opening <?php tag or after the closing ?> tag. In fact, most modern WordPress coding standards recommend omitting the closing ?> tag entirely in pure PHP files to prevent this exact issue.
1. The Invisible Culprit: UTF-8 BOM
If you’ve checked for extra spaces and found none, the issue might be a Byte Order Mark (BOM). This is an invisible character added by some text editors (like Notepad) at the start of a file. PHP’s header function cannot work if the BOM has already been output to the browser.
Use a professional editor like VS Code or Sublime Text and ensure your file encoding is set to “UTF-8 without BOM”. You can also run this command on your server to find files with BOM characters:
# Detect and remove BOM from PHP files
grep -rIl $'^xEFxBBxBF' . -ext php2. Output Buffering as a Workaround
While fixing the root cause is best, you can “mask” the error by enabling Output Buffering. This tells PHP to hold all output in a buffer before sending it to the browser, allowing headers to be modified at any time. Add this to the very top of your wp-config.php:
# Enable output buffering
ob_start();3. Common “Redirect” Conflicts
This error often pops up when using wp_redirect() or `header(‘Location: …’)`. In WordPress, you should always use the template_redirect hook for redirects to ensure no content has been sent yet. If you call `wp_redirect` inside a template file (like `header.php`), you’ll almost always trigger this warning.
4. Diagnosing the Error Message
The error message is your map. It usually looks like this:
Output started at /path/to/file.php:12
This tells you exactly where the “output” began. Go to line 12 of that file and look for anything outside of PHP tagsāeven a single blank line or an accidental echo will break the headers.
Conclusion
Headers are delicate. By ensuring your files are saved in the correct encoding and omitting closing PHP tags, you eliminate the most common sources of this frustration. If you’re encountering persistent header issues on a complex WooCommerce site, our WordPress Support Team can help isolate the conflict.


