Recently a friend of mine encountered a warning when he tried accessing WordPress login portal to log into his website. The warning looked something as Warning: Cannot modify header information – headers already sent by (output started at /path/blog/wp-config.php:39) in /path/blog/wp-login.php on line 42
Though the error was not exactly the same as I have mentioned above because the path mentioned in the bracket and after the bracket was something else (related to the theme he had installed and activated). He talked to me about the problem and his requirements about the theme. He and I, both knew that it was something related to the theme he had just installed but his main requirement was that he wanted to use the same theme desperately.
I looked for the solution to this problem and tried a number of things to make the theme work and login back into the wp-admin portal of his website, but here I am going to talk about the working method to rectify this warning and make things work for you. First of all, let us understand the reason behind this problem.
Reason Behind This Problem:
The main reason behind this problem is the presence of spaces, newlines or other stuff before an opening <?php or closing ?> tag, in the filename.php file. This filename.php is the one mentioned in your warning message and will tell you the exact location i.e. the line number which is erroneous.
Interpretation of the Warning Message:
For the 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, the problem is at line #34 of
wp-config.php, and not on line #42 of
wp-login.php. Line #42 of
wp-login.php is the one that is being affected by the excess whitespace at line #34 of
Solution of the Problem:
- 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.
- Check that the very first characters are <?php and the very last characters are either NOT a PHP closing tag or a closing tag ?> with no blank lines or spaces after it.
- Before saving, or use the Save as dialog, ensure the file encoding is not UTF-8 BOM but plain UTF-8 or any without the BOM suffix.
To be sure about the end of the file, place the cursor between the ? and > and remove any extra space between the two symbols. Note that, it may seem as if there are no spaces between the two but it may be present so do check for that.
Save your file without making any more changes as even a single space or change may bring the error back.
This is how it should not look like:
<?php some code; ?> <?php some other codes; ?>
This is how it should look like:
<?php code; some other code; ?>
After you have saved your file, upload it to your file manager by deleting the previous file and save your changes at the backend.
Now try opening the wp-admin portal of your website. Congratulations. You can enter in and work on your site again.