Here’s a frustrating yet common WordPress error that can appear out of the blue, bringing down your site in one fell swoop:
“Warning: Cannot modify header information – headers already sent by (output started at…”
What’s worse is that this error continues, listing paths to important files on your server which is a potential security risk.
But not to worry! It’s one of the easier errors to resolve and in this post I’ll show you how to fix it as well as how to hide error messages from showing on the front-end of your site.
Maybe it’s a Heady Problem?
Sure, this error may seem intimidating and almost like there’s an issue with your theme’s header.php file or something similar, but it actually has to do with extra spacing in one of your files. Sometimes they get added on unintentionally or automatically and need to be adjusted.
The error displays itself when there are:
- Blank lines at the top or bottom of a document
- Too many spaces before, in between or after the beginning
<?php
and ending?>
PHP tags - There are too many unneeded spaces or blank lines in a specific part of a document
In order to fix the spacing issue, you need to first know where it’s happening. Fortunately, the error message lets you know which file and line is affected. Keep in mind that you may see this sequence multiple times on the page which means there are multiple files that need fixing.
Here’s the basic structure to look out for in order to decipher the broken file:
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 #
The first file listed as /path/to/file/broken-file.php would be the one that needs fixing and the #
character directly after it would be replaced with a number which would tell you which line you need to fix.
The second file written in this structure as /path/to/file/affected-file.php is the file that isn’t able to work properly because the first file is broken. The #
symbol at the end in a real world example would be a number which indicates the line in the document that’s affected and not able to work.
Here’s an example of what this error could look like on your site:
Warning: Cannot modify header information – headers already sent by (output started at /home/name/you-site/wp-content/themes/your-theme/custom-functions.php:1) in /home/name/your-site/wp-includes/pluggable.php on line 876
In this example, name
would be the username of your cPanel or hosting account and your-site
would be replaced with the folder name where your site is stored. The error you would actually see would look differently, but it should give you a good idea of what to expect.
In this example, custom-functions.php within my theme’s folder is the document that needs fixing and the error is on line one.
Fortunately, it’s not terribly difficult to fix this issue even though it may seem intimidating at first.
Read on for your options.
Heigh-Ho, It’s Off to Work We Go Fixing Errors
There are two main ways you can fix the “Cannot modify header” error. If you get stuck along the way, feel perfectly free to get in touch with our expert support team. They can also help you with just about anything WordPress-related, they’re available 24/7 and they’re happy to help you out.
They would otherwise be eagerly waiting until you ask them a question so you may as well stop by if you run into troubles, especially when premium and expert support is included in your WPMU DEV membership. If you’re not a member, you can still try us out for free and ask an expert for help.
Fix #1: Upload a Fresh Copy
When you read the error message and you determine that the broken file is a part of the WordPress core or it’s otherwise an inherent file of a plugin or theme, there’s a quick fix available.
If it’s a regular plugin or theme file, you can uninstall and re-install it.
If you would rather not do this or a WordPress core file is affected, you can download a fresh copy and extract the ZIP archive to your computer. Locate the file that’s broken on your site and replace the existing one on your server with the fresh copy.
You can do this with the help of FTP, SSH or directly through cPanel.
Fix #2: Edit the Trouble File
Once you have identified the problem file, you can download a copy of it through FTP or SSH, or you can edit it directly in cPanel.
Clear any extra blank lines or spaces at the beginning and end of the document with your backspace button or Delete button for PC. Also, be sure there are no spaces before, in between or after the <?php
tag at the beginning of the file. The same goes for the ?>
tag at the end.
If the final line of the document doesn’t end in a ?> tag, then be sure there are still no spaces after the final character of the last line.
Save the file and upload it back to your site in the same place, overwriting the original file.