One issue that WordPress users often come across is the Headers already sent warning. If you’ve encountered this issue before or are curious about how to fix it, you’re in the right place.
In this article, we will explore what causes the Headers already sent warning in WordPress and provide step-by-step solutions to resolve it effectively.
Headers already sent
Headers already sent is one of the most common errors seen on the WordPress website. When encountered the issue you may see the following warning on the admin dashboard:
Warning: Cannot modify header information - headers already sent by (output started at...)
It is usually because there are spaces, new lines, or other stuff before an opening
<?php tag or after a closing
?> tag, typically in wp-config.php.
This can also happen in other edited PHP files that are theme templates, so please check the error message, as it will list the specific file name where the error occurred (see “Interpreting the Error Message” below).
Replacing the faulty file with one from your most recent backup or one from a fresh WordPress download is your best bet, but if neither of those are an option, please follow the steps below.
Just because you cannot see anything does not mean that PHP sees the same.
- Download the file mentioned in the error message via FTP or the file manager provided in your host’s control panel.
- Open that file in a plain text editor (NOT Microsoft Word or similar. Notepad or BBEdit are fine).
- Check that the very first characters are with no blank lines or spaces after it.
- Before saving, or using the Save as dialogue, ensure the file encoding is not
UTF-8or any without the
To be sure about the end of the file, do this:
- Place the cursor between the ? and >
- Now press the DELETE key on your computer Note to MAC users: The “DELETE” key on a PC deletes characters to the right of the cursor. That is the key note here.
- Keep that key pressed
- For at least 15 seconds
- Now type > and
- save without pressing any other key at all.
- If you press another key, you will bring the problem back.
- DO NOT PUT CODE IN UNNECESSARY CODE BLOCKS, PUT THEM IN A SINGLE PHP BLOCK.
<?php some code; ?> <?php some other codes; ?>
<?php code; some other code; ?>
Upload the file back to your server after editing and saving the file.
Note: Also check the encoding of the file. If the file is encoded as UTF-8 with BOM, the BOM is seen as a character that starts the output.
Interpreting the Error Message:
If the error message states:
Warning: Cannot modify header information - headers already sent by (output started at /path/blog/wp-config.php:34) in /path/blog/wp-login.php on line 42, then the problem is at line #34 of
wp-config.php, not line #42 of
wp-login.php. In this scenario, line #42 of
wp-login.php is the victim. It is being affected by the excess whitespace at line #34 of
If the error message states:
Warning: Cannot modify header information - headers already sent by (output started at /path/wp-admin/admin-header.php:8) in /path/wp-admin/post.php on line 569, then the problem is at line #8 of
admin-header.php, not line #569 of
post.php. In this scenario, line #569 of
post.php is the victim. It is being affected by the excess whitespace at line #8 of
Also Read: How To Fix the HTTP 499 Error