Interpreting error messages in WordPress can be a time-consuming process. Finding an adequate solution to the problem is equally as difficult.
To keep your website running like clockwork, you need to prevent long periods of downtime.
Find out how to fix the “Cannot Modify Header Information” error in WordPress and get your site up and running quickly.
What Does “Cannot Modify Header Information – Headers Already Sent By” Mean?
The “Cannot Modify Header Information – Headers Already Sent By” error indicates that a .php file cannot execute because an output is being sent before calling an HTTP header. Headers always need to precede the output.
The most common causes of the "Cannot Modify Header Information" error are:
- Whitespaces before the opening <?php token.
- Whitespaces after the closing ?> tag (if one is present).
- An HTML block is in front of the header within the .php file.
- Statements that produce output, such as print or echo, are being called before the header.
- Issues with an installed plugin.
How to Fix Warning “Cannot Modify Header Information”?
The warning message tells you which file or files you need to review to fix the issue.
In this example, the warning message indicates that the plugable.php file cannot execute due to an issue within the wp-config.php file.
Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/example.com/wp-config.php:33) in /home/public_html/example.com/wp-includes/plugable.php on line 1063
You need to access and check the code within the wp-config.php file.
The message also provides the path to the file /home/public_html/example.com/wp-config.php. The number 33 points out the exact line within the code causing the error.
The file path and the code line number are an excellent starting point when troubleshooting.
Corrupted PHP File
Use cPanel or an FTP client to access the server the website is located on. It is recommended to back up files before editing them.
The examples in this guide are presented using cPanel.
Edit the File
1. Locate the file by using the path from the warning message. You can also use the search bar at the top of the cPanel dashboard.
2. Select the file and click Edit.
3. Find the code line number specified in the warning message. Use the Go To Line option to locate lines in lengthy files quickly.
4. Remove any whitespaces preceding the opening <?php token.
5. If the file contains a ?> closing tag, ensure that there are no whitespaces after the tag.
6. Click the Save Changes tab once you remove all redundant whitespaces.
Once you reload your webpage, the error message should disappear.
Move the Header Statement
Raw HTML elements in a .php file are rendered as a direct output. If an HTML element is placed before a header call, it can cause the “Cannot Modify Header Information – Headers Already Sent By” error.
To fix the error, place the HTML block after the header statement.
Functions that produce output such as vprintf, printf, echo, flush, and print statements must follow HTTP header calls.
Review the .php file specified in the error message and correct the code. Always position header calls before the output producing elements and functions.
Replace the File
If you cannot locate the corrupt file or you are hesitant to edit the code, you can replace the entire file instead.
1. Download the latest WordPress version.
2. Use an FTP client or cPanel to upload the new version of the file to your server.
3. Overwrite the existing corrupt file with the new version.
4. Reload the previously unavailable webpage.
You can upload and replace entire WordPress folders if the warning displays issues in multiple files.
Find the Plugin that Causes the Error
A faulty plugin can cause the “Cannot Modify Header Information” error.
1. Access your WordPress dashboard.
2. Deactivate and then Activate each plugin, in turn, to determine if one of them is causing the issue.
3. Refresh the affected webpage after every change you make.
Focus on the recently installed or updated plugins. The error will reappear once you turn on the failing plugin.
Gather as much data as you can during this process and inform the plugin developers of the issues you encountered.
By following the instructions in this guide, you have successfully identified and resolved the “Cannot Modify Header Information” error.
Warning messages that flag similar issues are not uncommon in WordPress. The presented solutions are applicable in most cases with related underlying causes.