One of the most frustrating and common issues developers and site owners encounter is the “Warning: Cannot modify header information - headers already sent” error in WordPress.
Unlike a complete site crash, this PHP warning usually appears at the top of your screen, often breaking your site’s layout or preventing you from logging into the wp-admin dashboard. In this technical guide, we will break down what causes this error and exactly how to fix it.
What Causes the “Cannot Modify Header Information” Error?
When a browser requests a web page, the server sends HTTP headers before it sends the actual HTML content. These headers contain crucial information like cookies, redirects, and content types.
In PHP, headers must be sent before any actual output (HTML, plain text, or even a blank space) is generated. If a PHP script accidentally outputs a blank space or a character, PHP immediately sends the HTTP headers. Later, if WordPress tries to send a cookie (like when you log in) or perform a redirect, PHP throws a fatal warning because the headers have already been dispatched.
Common causes include:
- White Space in PHP Files: Extra spaces or blank lines before
<?phpor after?>in files likewp-config.phporfunctions.php. - Corrupted Plugins or Themes: Poorly coded plugins outputting content prematurely.
- UTF-8 Byte Order Mark (BOM): Saving a PHP file with BOM encoding.
Step 1: Read the Error Message Carefully
The best part about this error is that it tells you exactly where the problem originated. A typical error looks like this:
Warning: Cannot modify header information - headers already sent by (output started at /public_html/wp-content/themes/yourtheme/functions.php:14) in /public_html/wp-includes/pluggable.php on line 1224
How to decode this:
- The first part
(output started at ... functions.php:14)tells you exactly which file and which line number caused the premature output. This is the file you need to fix. - The second part
(in ... pluggable.php on line 1224)tells you which core WordPress file failed to execute its header function because of the premature output. Do not edit this core file.
Step 2: Remove White Space from the Culprit File
Once you’ve identified the problematic file (often wp-config.php or a theme’s functions.php), connect to your server via FTP or File Manager.
Open the file in a code editor and check for the following:
1. Leading Spaces: Ensure there are absolutely no spaces, tabs, or blank lines before the opening PHP tag.
<?php
// Correct: Tag is on line 1 with no spaces before it
2. Trailing Spaces: If the file ends with a closing PHP tag ?>, ensure there are no spaces or lines after it. Better yet, in pure PHP files, it is a standard practice to completely omit the closing ?> tag to prevent this exact error.
Step 3: Deactivate Problematic Plugins
If the error points to a file inside a specific plugin’s folder (e.g., wp-content/plugins/bad-plugin/), that plugin is the culprit.
If you can access wp-admin, simply deactivate the plugin. If the error has locked you out of the admin dashboard (similar to a White Screen of Death), you can disable the plugin manually:
- Access your files via FTP or cPanel.
- Navigate to
wp-content/plugins/. - Rename the problematic plugin’s folder (e.g.,
bad-plugintobad-plugin_disabled). - Refresh your site.
Step 4: Ensure Correct File Encoding (No BOM)
If there are no visible white spaces, your code editor might have saved the file with a Byte Order Mark (BOM). The BOM is an invisible character at the very beginning of the file that triggers PHP output.
To fix this:
- Open the file in a modern code editor like VS Code or Notepad++.
- Change the encoding to UTF-8 (Without BOM).
- Save and re-upload the file.
Proactive Hosting Solutions
Troubleshooting PHP errors manually can be tedious. A reliable infrastructure goes a long way in preventing environment-specific errors. By utilizing our premium WordPress Hosting plans, you get automated backups, staging environments, and expert support to resolve these issues quickly.
If your site is completely down and you aren’t seeing this header error, you might be facing a different issue. Check out our guide on troubleshooting the Error Establishing a Database Connection for further assistance.
Ensure smooth cookie handling and redirect loops protection with a reliable Pakistan shared hosting environment.
