How To Fix WordPress Cannot Modify Header Error
Adding themes, installing plugins, creating pages, running a WordPress website involves plenty of things. Every time you make an update or modify a page, you run a test to ensure that the page is error-free and can function without gaps, right.
Yet, getting everything perfect in a single instance is not necessary and there might prevail certain errors or issues that can cause your site to break. Of all the issues and errors, one that every developer would have encountered while working with WordPress is Cannot Modify Header error.
Something, like this:
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 #
Does this ring a bell? Surely, it does.
It is one of the most common error, however, it is not just the warning that scares you but the fact that as the error continues to prevail, it links paths to the important files within the website or stores on the server. This is a notion of grave concern, mandating a quick fix. But how?
Don’t worry, this article will help you get rid of such errors, let alone fix them to keep your site safe, secured and well functioning.
Before, we delve into the specs of how can you fix the cannot modify header error, it’s important to know the cause. What are the plausible events that might lead to the above?
When Do You Encounter The Error
As the error specifically suggests header error, there has to be something in the header.php file that accounted for the same. Primarily, it is because of an extra space added in the file, either deliberately or accidentally and you need to fix this to get rid of the error.
The possible reason why you get a header error include:
- There are multiple blank lines embedded within the document, rather at the top or bottom.
- Presence of too many spaces, either before or in between or after the initial PHP tag of <?php and ending ?>.
- The occurrence of multiple blank lines or unwanted spaces in specific areas or parts of the document.
There are multiple blank lines embedded within the document, rather at the top or bottom.
Presence of too many spaces, either before or in between or after the initial PHP tag of <?php and ending ?>.
The occurrence of multiple blank lines or unwanted spaces in specific areas or parts of the document.
Imagine that the error displayed is something like this :
Warning: Cannot modify header information – headers already sent by (output started at /home/name/your-site/wp-content/themes/your-theme/createcustom-functions.php:1) in /home/name/your-site/wp-includes/plug-play.php on line 876
Here, you have a file with the name, createcustom-functions.php. The file is stored in the your-site folder with the name being the username of the admin. The error exists in line 1 of createcustom-functions.php. And the error is the direct outcome of glitches in the plug-play.php file on line number 876.
So, you see it’s not tough to decode the error message, right? All you need to do is located the file and fix the issue, on the go.
Let’s see how!
Fixing the Error - Cannot Modify Header
So, there are two ways by which you can seamlessly fix the cannot modify header error.
- Uploading a Fresh Copy
The first and easiest quick fix is to upload a new copy. To deploy the solution, we need to do the following.
Once, you have read the entire error information and determine which part of the WordPress file is broken. It could either be a file belonging to WordPress core or it could be an inherent file of a WordPress theme or a plugin that you installed within your website.
- In case, the error is due to the presence of a regular plugin file or a WordPress theme file, the best you can do is first, uninstall the plugin/theme and then install it once again. This way you remove all anomalies that might have been integrated within the file.
- In case, the error is not because of the above and there exists an error in the WordPress core file, what you can do is download an all-new copy of the file, extract the ZIP file within your computer. Locate the file that leads to the errors and replace them with the infected one, running on your server.
The above can be done either through the cPanel or through FTP, or SSH.
- Reconfigure the Trouble File
In this process, after you have figured out which file is infected, you can log in to the FTP or SSH to download the file. You can also visit the cPanel to directly download the file.
- Now, click open the file.
- Remove any blank spaces or lines, occurring at the start or end of the document.
- Make sure that there does not exist any space either after or before, or in between the <?php ?> tag at the end of the file. In case, the end of the document does not have the tag ?>, edit the same to be sure that the file does not incorporate unwanted spaces.
- You can now save the file and then upload the same back to your site overwriting the original file.
And that’s all! Chat Now