Resource icon

Fix the “Cannot Modify Header Information” Error In Wordpress with These Steps

Fix the “Cannot Modify Header Information” Error In Wordpress with These Steps

Header code errors are pretty common in WordPress. They seemingly flash on your screen out of the blue. While the errors can be frustrating, there’s a quick fix to it. In this article, we’ll explain how to solve the “Cannot Modify Header Information” error in your Wordpress website and bring it back to normal.

What is the Header Information Error Warning in Wordpress?

Wordpress is written in PHP. When you create a website in PHP, PHP basically generates the web pages for you. There are three main sections in your website:
  1. Header
  2. Body
  3. Footer
The header section contains the metadata among other information. This remains invisible to the user. Developers are free to modify the header section. For example, they may be asked by their owner to install the Facebook Pixel into the website. Page headers are usually where they are placed. At times, this can throw an error which reads something like:

Code:
Warning: Cannot modify header information – headers already sent by (output started at /path/to/file/broken-file.php:#) in /path/to/file/affected-file.php on line #
In most cases, extra blank space or a typo error is the culprit, but incorrect PHP encoding, Plugin errors, or header misplacement can also cause this error.

How to Fix the Error?

The problem is easier to solve than you think. Here are the best two ways to deal with it. But before that, if you see that the error is caused by a plugin, then remove and reinstall it and see if the error is fixed. If not, keep it uninstalled and contact the plugin owner regarding the error.

If the header error isn’t caused by a plugin, then follow these methods:

Edit Corrupted Files

Since the error might be caused by a typo, first thing should be to check for it. Look at the source of the error and check if there are any extra spaces or unnecessary characters. If there are, fixing those should solve the problem. Here’s how to do it:
config.png

  • Locate the source of the error from the error message which is “Line #”.
  • Download the website code to a local computer using FTP. (You should never edit a live website)
  • Now open the file and look for the line #.
  • Scout for typo errors and fix them.
  • Most common error is the space before and after the <?php > tags. There shouldn’t be any spaces.
  • Once done, upload it back and check if the error is solved.

Relocate Header Statement

As a rule of thumb, in PHP, the header should always supercede the body in the order a web page is loaded. So the header should load first followed by the rest of the code. But if the rest of the code, including unparsed HTML, get executed before the head section, then chances are you will get header error warning.

This problem can be solved by relocating the head section above the code that’s throwing the error. First, locate the statement from the error message. Now cut the header section and paste it above the faulty code. This should resolve the error and your website should be back to normal.

The key takeaway from this error is that you should always check for typos and whitespaces when installing a plugin and writing a code snippet. The header information should be prioritized in the order when loading a web page.
Author
bhawanisingh
Views
14
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from bhawanisingh

Top