Don’t Panic! Fixing WordPress Error: Warning: Cannot modify header information – headers already sent by…

If you ever get the infamous wordpress Headers Already Sent PHP error message on wrodpress it is generally solved by removing whitespace at either the beginning or the end of the file in question. I recently had it on a wordpress site where I’d modified the functions.php file using the wordpress text editor.

It took a while to figure out exactly what the issue was as I tried all the usual fixes holding down delete before <?php and replacing <?php manually etc. The problem actually turned out to be the text editor I was using. The WordPress editor didn’t work, neither did Dreamweaver and neither did File Manager in cpanel. In the end what fixed it for me was using notepad to delete the invisible white space.

For example this was my error:

Warning: Cannot modify header information – headers already sent by (output started at /home/MY-SITE/public_html/wp-content/MY_THEME_FOLDER/SOME_FILE.php:1) in /home/MY-SITE/public_html/SOME-FOLDER/ANOTHER_FILE.php on line 1000

Follow these Instructions (please note this is usually what the issue is and will fix this error 95% of the time)

  • Firstly look at the error message… It’ll say that the (output started at … followed by a file name and a “:” then a line number (You can ignore the second file name as that is the file that has inadvertantly included the whitespace)
  • Download the file in question via FTP (in wordpress it’s normally functions.php but could be any other PHP file from the theme folder i.e. ../home/wp-content/themes/YOUR_THEME_FOLDER/functions.php)
  • Open that file in Notepad
  • Look at the line number that the error message gives – it’ll probably either be 1 or the last line.
  • If it’s :1 put the cursor at the beginning of <?php and click backspace – then save and upload. If that doesn’t work delete the first line and manually rewrite it back in then save and upload.
  • If it’s the last line put the cursor at the end of the last character and click delete then save and upload. If that doesn’t work delete the last line and manually rewrite it back in then save and upload
  • Note (sometimes this error is casued becasue <?php is missing at the beginning or ?> is missing at the end)
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

Magento – How to Delete all Products Data with MySQL Truncate

Next Post

How To Set Up a Cron Job for Magento in Cpanel

Related Posts