It’s funny how a tiny slip-up can render your WordPress site completely dysfunctionally. We are, of course, talking about the infamous Warning: cannot modify header information – headers already sent by pluggable.php WordPress error. If you happen to be the one stuck facing this error, then you have come to the right place. In this WordPress tutorial, we will discuss why this error occurs in the first place, and look at solutions that are sure to take care of the problem once and for all.
Table of Contents
What you’ll need
Before starting this tutorial, you’ll need the following:
- Access to your Hosting control panel or FTP
Why you get Cannot modify header information – headers already sent by error
Let’s take a look at an example of this error so that we can understand it better. The error commonly pops up in the following form:
Warning: Cannot modify header information – headers already sent by (output started at /public_html/wp-content/plugins/my-plugin/my-function.php:#) in /public_html/wp-includes/pluggable.php on line #
As you can see, there are two files mentioned by the error. The first file (in our case: my-function.php located at /public_html//wp-content/plugins/my-plugin/) is the chief culprit of the error. This is our custom code that is used to override the core functionality provided by WordPress. The core functionality in question is in the pluggable.php file (a core WordPress file which is the same for every WordPress installation). Basically, there is a problem in the first file which is preventing the second file to function properly.
The major cause of this error are blank spaces present in the first file. These could be blank spaces at the top or bottom of the file, unnecessary blank spaces anywhere in the file or even blank spaces between the <?php and ?> PHP tags. In fact, because programmers can (and usually do) mistakenly type extra spaces when writing code, this error is more common than you’d expect. The line # indicated in the error message corresponds to where the problem is specifically originating – it will help you eradicate it without too much fuss.
Fixing cannot modify header information – headers already sent by error
Now that you know what causes this error, you can move on to fixing it for good. We will show you two methods of eliminating this problem, which you can attempt either separately, or in order, if attempting it seperately doesn’t work.
Option 1 – Editing corrupted files
The first option when troubleshooting the Warning: cannot modify header information error is to manually edit the faulty file. You are already supplied with the necessary information to locate the problem in the error message (remember, it’s the first file in the message). All you need to do is open up this file, either through an FTP client like FileZilla, or through File Manager.
Essentially, all you’re looking to do here is to remove extra spaces present in the file. A good place to start would be the line # mentioned in the error message. From there, you can continue to parse the rest of the file and look for additional unneeded spaces/blanks until the end of the document.
Make sure to pay special attention to the starting and ending PHP tags. There should not be spaces before or after the <?php tag, as well as the ?> tag. Also, the last line of code should not be followed with a blank line or extra space.
PRO TIP: In many text editors you can remove white spaces automatically. For example, to remove white space in Atom, select all the code and navigate to Packages -> Whitespace -> Remove Trailing Whitespace.
Option 2 – Replace corrupted files
Of course, editing multiple corrupted files can be difficult. Files could belong to a plugin or theme you recently incorporated in your site, or could even be a core WordPress file.
If the error is indeed caused by a plugin or theme, all you need to do is re-install it. Doing this fixes the error in most cases. On the other hand, if a core WordPress file is the culprit of the error, your best bet is to get yourself a clean copy of WordPress and replace the corrupted file on your installation with the one present on the clean version. This will ensure that the corrupted file has been restored to its original state while keeping the rest of your WordPress installation intact. Now, simply reboot and make sure that the error is fixed.
Whether you paste a code snippet to your file, insert a new plugin/theme or write code manually, you carry a risk of adding extra blank spaces to the file. These seemingly innocent blank spaces can come back to bite you in the form of the Warning: cannot modify header information – headers already sent by WordPress error.
In this tutorial, we saw how to fix these errors, so that your site can function as intended once again. For more tutorials related to WordPress, visit our WordPress tutorials section.