WordPress: Cannot Modify Header Information

I have created and edit the templates for my WordPress blog long enough to come across a few confusing errors. While I have had good success solving many of the errors fairly quickly, there is one that has continuously come up, and caused my blog from loading.

Recently, however, I managed to find the cause of this common error, and since then have quickly corrected any problems that have caused the error. This post explains the error, and how I solved the problem.

The Error

Sometimes when I edit my WordPress template files, I receive the following error message when I attempt to view my blog:

Warning: Cannot modify header information – headers already sent by (output started at [path to problem file]) in [last file requested] on line [line number]

The text in italics is dynamic and is different depending on the files and line numbers that caused the error.

For someone like me, who isn’t very fluent in PHP, errrors such as this are very cryptic. At least the error message did mention two files that I could look into to see if I could find the problem.

The Solution

The first thing I did was look into the first file specified by the error message. I slowly looked through the file, looking for anything that didn’t look right. Nothing in the code jumped out at me as being wrong. I then closed the file and looked for the second file specified in the message.

The second file, however, was a WordPress file as I had been editing my template in WordPress. Realizing that the WordPress file was probably not the cause of the problem, or I would have had the error once I upgraded, I re-opened the original file.

After reviewing the contents of the file a second time, I thought maybe some strange characters were embedded in the file. I double-checked the spaces and carriage returns, and then saved the file.

The error still came up in the web browser. I went back to the file and removed all lines and characters from the end of the file (below the ‘?>’ tag), and then resaved the file. After doing that last step, the pages to my blog were displayed again without any problems.

If you experience the same error, check to ensure you don’t have any strange characters after the ‘?>’ tag at the bottom of a file.

Follow Me