When attempting to save a WordPress post you recieve the following error message
Warning: Cannot modify header information - headers already sent by ... in ... on line ...
There are many issues that may cause this error – all are code related, so you will need the ability to disable plugins, change themes and edit the websites PHP files to fix the error.
Step 1 – find the culprit
In the error message you will see ‘headers already sent by’ followed by a path and file name.
The path and the file name will tell you where the error is – but not which line. The line number mentioned is where the WordPress code conflicted.
If the path includes ‘plugins’ – use the path to work out the name of the plugin and try disabling it from the WordPress administration.
If the path includes ‘themes’ – use the path to work out the name of theme and try changing themes from the WordPress administration.
Does the error message still happen? If not you’ve found the culprit. If it still happens you will need to continuing the process of disabling plugins and changing themes until resolved.
Step 2 – fix the code
This is the hard part. You know the path, you know the file – but you don’t know the line that cuased the error.
Open the file using your prefered method – typically this is done using FTP (best option), through your host cpanel account, or using the WordPress code editing feature (this is a little more risky – if you do it wrong WordPress may not load and you will not be able to undo the changes).
Check for the following issues:
- If the file has a blank line before the opening <?php you will need to delete the blank line. PHP files must start with <?php followed by a line break
- (only an option if using FTP) Open the file using notepad++ from the Edit -> EOL Conversion menu make sure that either Windows or UNIX is selected (UNIX is most probably the most suitable option here), from the Encoding menu make sure that ‘Encode in UTF-8’ (or Encode in UTF-8 without BOM) is selected. Save the file.
- Check the end of the file – if there is there a ?> you can delete this. PHP files do not need to be closed – this doesnt create issues on itself, but does when there is a space between them. E.g. ? > would create issues.
- Copy the code in the PHP file and run it through an automated PHP code checker, such as phpcodechecker.com
Still got the problem?
Try contacting the developer of the plugin or theme you identified in step 1.
Leave a comment below if you find or know of other solutions for this problem – others will appreciate it.