Warning: Cannot Modify Header Information – Header Already Sent By

Image credits : wikipedia commons

This PHP header error results from extra empty spaces that are not suppose to be within your files. You could have unknowingly created them when you are modifying WordPress or your Theme files. You will see something similar to the following error message.

Warning: Cannot modify header information - Header already sent by (Output started at /blog/wp-config.php:34)

Locating the error

We can troubleshoot this issue by looking at the file which the error message is pointing to. Looking at the above sample error, we can see that it points to wp-config.php

This error usually happens in wp-config.php or functions.php, because both files are most frequently edited by users. If you happen to be editing a theme file other than functions.php, then it's highly possible that the error is from the file that you have just edited. 

Therefore, it's always good practice to keep a list of files that you have worked on. In programming, we call this file a changelog.

Troubleshooting

You will need to use your FTP program to edit the file on your server.

  1. Use your FTP program to login to your web server.
  2. Navigate to your file, in the example, it's the wp-config.php.
  3. Open up wp-config.php file.
  4. Look for <?php at the very beginning of the file. Remove any empty space before <?php
  5. The <?php which is the PHP opening tag should be at the very first line of the file within wp-config.php
  6. Look for any ?> sign at the end of the file, it there is any, you will need to remove any empty space after it.
  7. If you cannot find any ?> sign at the end of the file, you will not need to do anything. Just to play safe, you can remove empty lines.
  8. If your error points to functions.php, you can carry out the same procedure.

Error caused by plugin

If you are unable to locate the error, and unable to fix it. There is a high chance that it's coming from a plugin. You can disable all plugins to see if it fixes your issue. If indeed it's cause by a plugin, you can start finding it by enabling one plugin at a time, and re-loading your website. 

After you have found the plugin that's causing this issue, you will need to disable it and report this issue to the plugin developer.

External Resources

  1. How to fix "Headers already sent" error in PHP (stackoverflow)
  2. Cannot modify header information - headers already sent (wordpress.org)
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.