WordPress cannot modify header information, How I fixed

wordpress cannot modify header information , headers already sent by…

This is an annoying little error that seems to be coming up a lot lately with various WordPress websites across the Internet. If you punch in these search terms “wordpress cannot modify header information”, you’ll see a ton of results, with people obviously frustrated and trying everything they can to get to the bottom of it.

I had a not-so-nice encounter with this error recently, for the first time, and it came to me completely out-of-the-blue. Or so it seemed.

I had a site that was working perfectly with no problems. Then one day I tried to log in and whenever I hit the administration screen BAM: “wordpress cannot modify header information, headers already sent by…”. Great! What the heck? Where did this come from and why now?

I searched for some answers on the WordPress forums and support site. They do have a short description of the problem and a few paragraphs on how to combat it. Unfortunately the problem seems to be too widespread and their attempt at help did not apply in my situation. After trying their suggestions, and the suggestions of a few other websites complaining about the same problem, I realized I was running into a brick wall. None of the problem-solutions that were presented to me either worked or applied.

I realized I had to do what I do best… tackle this one on my own with ingenuity, logic and my problem solving skills.

I believe my error was caused by a recent plugin, although I cannot prove this. I cannot prove it because I have not spent the time to try and replicate it. Time is a commodity I fall short on these days but by having a theory and working my way around that theory from many aspects and angles I was able to solve the error within an hours time.

Prior to the error I had installed a new plugin that I’ve never used before. It was the PC-Google-Analytics Plugin. The plugin seemed to work fine when it was installed and perhaps it does work fine for 99% of the websites it is installed upon. However, this particular website that spouted the error to me had only 3 plugins installed and 2 of them were plugins that have been used for over a year with no problem. This one plugin was the only recent change to the WP site so it was suspect #1 in my book.

Since I could not access the administration page (wp-admin) tackling this problem meant thinking outside the box. Normally I could just log in and remove the plugin to see if the problem went away. And normally this may help with plugins that don’t modify header information, however, this particular plugin does modify header information – that’s how it places the Google Analytics code on the site to begin with. It modifies the header after evaluating who is visiting. One of the perks of this plugin was that it would apply the tracking code to the site if someone was visiting it – unless it was an administrator who was currently logged in. In that case it would omit the analytics code – because who wants to track them selves? Sounds like a decent thing to do, and it saved me the few minutes required to write that bit of code myself.

Unfortunately, the plugin was installed and seemed to work fine for a few days but within a week the site’s administration screen was down with that error “wordpress cannot modify header information, headers already sent by…”. Now again, I cannot prove that this plugin was the culprit, but I’m 99% sure. Maybe when I have more time I’ll try to replicate this problem on a new WP site to see if it was indeed the plugin as I suspect. If it was not the plugin, then something else is the culprit.

After reading a little bit more about the error “wordpress cannot modify header information, headers already sent by…” I was ready to tackle it. I traced the error down by looking at the line numbers that the error was reporting. These line numbers are deceiving because the true problem was not the code on those lines but something missing prior to those lines being read. I knew this already but these line numbers do provide an important piece of information: The file names themselves.

The fix for me was quite easy once I was confident I understood what was happening. Something (I suspect the plugin) had modified a couple of files in some way that broke the administration side of the website. The front-end worked fine, which is something a lot of other people are mentioning. Just looking at the site as a normal user everything appeared fine, but the moment you try to login or access the admin screen bam: “wordpress cannot modify header information, headers already sent by…”.

So how did I fix this?

First, I manually deactivated all WP plugins to be safe by modifying the wp-config file. This did not fix the problem because the files in question had already been affected by something (I suspect the plugin). Deactivating the plugin would have been fine if the plugin replaced the files it had modified with a copy that was unmodified, but this plugin did not do that (I’m not aware of any that do).

Then, I replaced the files that were being reported by the error with brand new copies from the exact same version of WP that I was using. In this case it was only 3 files that needed to be replaced, all located in the wp-includes folder of any WP site.


Again, these were the 3 files that the error was complaining about by giving me various line numbers. I knew the code was fine but this error seems to be common with mis-formatted files with improper PHP brackets. I swapped them out via FTP and bingo, the WP administration screen was accessible and everything worked fine after that. I was able to reactivate the other plugins that I believed were fine (one by one of course). I completely removed the Google Analytics plugin and washed my hands of it. The plugin uses (or modifies) load.php to eventually load the Google Analytics Tracking code.

The site has been fine ever since.

If you encounter this problem: wordpress cannot modify header information, headers already sent by…” I suggest replacing the problem files with known-good copies of the files in question after deactivating all your plugins. There may be other plugins in the wild that do the same thing.

In my situation none of the WP support documents were of any help in fixing this problem, nor were any of the other websites I researched, however they all give you some useful knowledge about the overall problem. If you approach a problem like this with an “Overview” perspective and apply a little ingenuity and Trial-and-Error, you should be able to overcome this and other errors.

Lastly, let me know if this was helpful to you!

Leave a Reply