Hostwinds Tutorials

Search results for:


Table of Contents


What Causes A "Cannot modify header information" Error?
Locating the error
How to Fix "Cannot modify header information" Error
Error Caused by Plugin

How To Fix A Cannot Modify Header Information Error In PHP

Tags: WordPress 

What Causes A "Cannot modify header information" Error?
Locating the error
How to Fix "Cannot modify header information" Error
Error Caused by Plugin

What Causes A "Cannot modify header information" Error?

Cannot modify header information errors are most commonly caused by extra white spaces (blank spaces) that are not supposed to be within your PHP files or other files already sending header information. This is a common issue with some web applications. It's usually added on accident when editing and modifying WordPress or your Themes files. Keep this in mind when you are making any edits to any WordPress files because it can prevent you from logging into the user dashboard, which means preventing you from managing the site properly. A single extra space can prompt this error. However, it's also possible that you installed a plugin containing files with extra space, causing WordPress to throw this error up.

It will look something like this:

Warning: Cannot modify header information - Header already sent by (Output started at /blog/wp-config.php:31)

Locating the error

This error mostly happens in the wp-config.php or functions.php. The reason is that these files are where users frequently editing. The error may be from the file that most recently got edited. It would probably be a good idea to check once you have finished the edited file and keep a list of files you have recently worked on.

How to Fix "Cannot modify header information" Error

If your site isn't running on WordPress, the error you see on the page will usually tell you where to look. To fix the error, you have to find out where it's coming from. In the example above, it's in the wp-config file on line 31.

Step 1: Go to the corrupted file and line number it identifies to see any extra spaces.

Step 2: Make sure there are no empty spaces before \<?php at the beginning of the file. The <?php, which is the PHP opening tag, should be at the very first line of the file.

Step 3: Make sure there are no empty spaces after?> At the bottom (If there is one, there is no need have to be ?> at the end).

Step 4: Make sure there are no extra blank spaces at the end of the code.

If the error points to the functions.php file, you should do the steps described above to ensure no empty spaces.

Error Caused by Plugin

If your site is running on WordPress and you can't find any extra spaces anywhere, there is a high chance that it's coming from a plugin. What you can do is disable all your plugins and see if the error is gone. If so, turn them on one by one, checking after each one to find the problem-causing plugin by reloading your website. Once you have found the plugin causing this issue, you could try re-installing it to see if it helps resolve the issue. If not, you will need to disable the plugin and report it to the plugin developer. Once the plugin developer fixed the issue, you could update and enable it.

Please note that Hostwinds is a website and server hosting provider. We do not generally provide website design or development assistance.

If you have further questions about this error, please reach out to us via LiveChat. And one of the support agents could assist you further.

Written by Hostwinds Team  /  June 5, 2021