Fix: Cannot modify header information – headers already sent

If this warning is currently bugging you and preventing you from accessing your WordPress Admin Panel, we have the simple fix available for you in this article.

WordPress Header Warning

So, you thought things were going well.  You made a few changes and things were going well and then all of a sudden you can’t save your posts, you can’t access your image library or after you logged out you can no longer get to the wp-admin page because of a warning that looks similar to this:

Warning: Cannot modify header information – headers already sent by (output started at /home/ in /home/ on line 850

What we want to look at is the first part of this warning.

This warning is stating that there is something wrong in you functions.php file, meaning, you made a slight change to the file and it needs to be addressed.

Question –

What did you recently change and why?

In my case today I added a string of code to functions.php and then removed it.  I thought everything fine and I saved the file.  So, what caused the error?

Well, in the functions.php file, you can absolutely not have a space before the <?php opening code.  I removed the space, save my file, and life was good again.

Additionally, I have a few other notes for your below.

  1. Do not close your php – Extra spaces can cause issues in functions.php, library.php, custom_functions.php, wp-config.php, class.wp-scripts.php, wp-blog-header.php, etc and so on…………    if you are not super skilled in php, you may not recognize where all of the spacing issues are.  One “fix” for this is to leave your php code open.  What this means is, remove the ?> if you have one at the end of the file that is causing issues.  Save your file.  If this does not resolve your issue, you may want to put it back.  The goal here is not to make changes to files you haven’t touched but to figure out what you DID touch and review the code closely where the change was made.
  2. Code Editor – Use a code editor when editing code, do not use a WYSIWYG (what you see is what you get) editor.  The reason for this is that the WYSIWYG editor will add additional code that you cannot see (unless you look at the text view of your tool).  It is wise to use NotePad++ or a similar program (your notepad on pc will do just fine as well) when editing code so that you can ensure that it is clean and that no spaces, whitespace, newline has occured.
  3. FTP – You can’t get to your wp-admin so now what?  You will need to use FTP to access your files and drilldown to the location (probably wp-content/themes/themename).    FileZilla, WSFTP are popular, I prefer WinSCP.