Cannot Modify Header Information – Headers Already Sent – Common PHP WordPress Issue Solution

This is probably way too common issue with the wordpress since it generates a lot of queries upon searching at any search engine. Even at the support of the wordpress people have asked such questions that there wordpress site is giving an error at the front page or else at the single page that:

Cannot Modify Header Information – Headers Already Sent by (output started at /public_html/index.php:1) in public_html/wp-includes/pluggable.php on line 876 – etc errors like this!

Let’s discuss the reason that why such error outputs at your wordpress and what is the solution to this problem. Since, it’s getting way to common.

Cannot modify header information php error

Cannot Modify Header Information – Headers Already Sent PHP Error Description and Solution:

Headers need to be called before any piece of the HTML code, but when this error outputs to the any site’s front page, then this means that actually headers are being called after the call of the HTML tag. Some hosts don’t like this behaviour and as a result give you the error. That is something like you are trying to send an email without the recipient email address. Many hosts just ignore this problem and PHP never outputs any thing but if you are getting this problem then you need to find out a solution to this, specially in case of wordpress.

Possible Reasons of this “Can’t Modify Header Information” Error:

There can be a lot of reasons, But the top most reasons which I can understand are written below:

  1. You got a poorly coded theme which is trying to output something before the headers information is sent.
  2. You got something in the code which is trying to print something at the top of the page just before header information is sent, so you need to care for the echo parts of php code.
  3. Your Core wordpress files have been changed and some unknown characters have been added, or else a viral code which is causing the problem.
  4. Some White space has been added before or after the <?php opening and ?> closing tags.
  5. There is something which is trying to output a code before the header() PHP code.

Thus, keep in mind the above possible reasons which can cause the error.

Solution of this Error – Can’t Modify Header Information:

Solution can be varied in your case, I’ll start from easy case to the extreme one where you will need to replace some files in the WordPress core.

Locating the Error in WordPress and solving it:

Understand the output of the error, if you are getting blank page and no error at your wordpress blog then you need to open up the wordpress debug mode which will help you show the error at the browser screen. For this Go to wp-config.php and edit it in some good text editor like Notepad++. Add the Following code of line in that : define(‘WP_DEBUG’, false); or if it’s already added simply change false to the true. Now, again open up the Browser and now you will get the error in wordpress instead of a blank page.

Secondly, you can also look into error_log file and can edit that using the same editor to look at the errors which your wordpress is generating. The error_log for the wordpress is located at the root of your public_html directory.

Now, suppose the error is like this:

Cannot Modify Header Information – Headers Already Sent by (output started at /public_html/index.php:1) in public_html/wp-includes/pluggable.php on line 876 – etc errors like this!

Troubleshooting the Issue of Header()

  • The problematic part is actually at the index.php , and any of the above reasons described is causing the problem at the line number one of the index.php and as a result of the above problems the pluggable.php is getting affected. So, you need to check the index.php first and then go to the pluggable.php. Both of them are the core wordpress files.
  • Second, thing which you can do is by disabling all the plugins one by one and keep on checking that did the error go? If you find the error causing plugin, then simply update it or else disable it. And then email the developer.
  • Go to the affected files and look for any white spaces before, after the PHP opening and closing tags. If there are any present then simply delete them. For the details guide refer to this wordpress codex: How To Solve Headers Already Sent warning Problem?
  • Replace the core wordpress file with the same version of the WordPress and check the Error type, Before replacing be sure to backup the original files, so if more errors appear along with that header error then kindly place back the original core files. If by replacing the new files the error resolve then issue is gone. If don’t then keep on reading.
  • Sometime adding the ob_start() at the start of your error causing code and ob_flush() at the end of the error causing file code will solve you the problem. Be sure to add them under the php tags since it’s also a php code.
  • Change the theme with the original wordpress theme, and if doing so removes the error, then you need to tweak your theme, remove any error causing problem.
  • If you are running an old version of theme, wordpress or plugin then kindly try updating that, but be sure to make the backup first.
  • At the end if you have tried all the possible solutions, then you can only do is to backup the wordpress wp-content folder and mysql database, if the core files are the only problem not the theme ones. And then place a new wordpress at the root of your hosting and then restore the wp-content as well as the mysql database. I’ll soon write that how can you actually refresh your wordpress installation without any error and problem. So, subscribe to talkofweb below.


1 Comment

  • You need to modify the index.php and add something inside php.ini, it is explain on the page below:


    Note: This will only resolve the header related error.