How to Fix the “Cannot Modify Header Information – Headers Already Sent By” Error
The “Cannot modify header information” error in WordPress typically occurs when there is an attempt to modify HTTP headers after they have already been sent. This issue is relatively common and can affect the functionality of your plugins, themes, and the WordPress core.
If you encounter this error message, it’s crucial to resolve it quickly to prevent any harm to your website’s performance.
This WordPress guide will walk you through the troubleshooting steps to fix the “Cannot modify header information” error. First, let’s explore the potential causes.
Download all in one WordPress cheat sheet
What Is the “Cannot Modify Header Information – Headers Already Sent By” Error?
The “Cannot modify header information” error happens when HTTP headers are changed after being sent, usually due to whitespace or output before or after PHP tags in files. If left unresolved, this common issue can disrupt the functionality of plugins, themes, and the WordPress core.
What Causes the “Cannot Modify Header Information – Headers Already Sent By” Error
In most cases, the “Cannot modify header information” error is caused by any output like misplaced text or extra whitespaces before the <?php opening tag or after the ?> closing tag in PHP files.
Conflicting code within plugins or themes and unexpected print or echo statements that generate output before headers are modified can also trigger this error message.
How to Fix the “Cannot Modify Header Information – Headers Already Sent By” Error
You can fix this common WordPress error by modifying your website files with a File Manager or an FTP client like FileZilla.
We’ll show you how to resolve the “Cannot modify header information” error using Hostinger’s File Manager, which is available on all WordPress hosting plans.
Important! Back up your WordPress website to avoid data loss during troubleshooting.
1. Identify the Error Location
The “Cannot modify header information” error message usually contains information about the file and line number where the error occurs. Here’s an example of what it might look like:
Warning: Cannot modify header information – headers already sent by (output started at /public_html/wp-content/plugins/plugin-name/function.php:4) in /public_html/wp-includes/pluggable.php on line 1300
From that, we know that the first output from the function.php file in line 4 causes the attempt to modify headers in the pluggable.php file in line 1300 to fail.
To fix this issue, we need to troubleshoot the faulty function.php file.
2. Edit the Faulty File
After identifying the error’s location, use Hostinger’s File Manager to check for and remove extra blank spaces from the faulty PHP file. Here’s how:
- Go to Files → File Manager from hPanel, then access the files of your WordPress website.
- Locate the problematic file, then double-click to open it.
- Remove any spaces before the <?php tag or after the closing ?> tag and the file’s last line of code. In the following example, the PHP opening tag should appear in line 1 instead of 4 without extra whitespace.
- Click Save and reload your website to see if it resolves the error.
3. Replace the Faulty File
If the error originates from a WordPress core file, you can replace the problematic file with the default one from the WordPress installation package. Here’s how:
- Download the WordPress installation package from the official website and unzip it.
- Locate the faulty file on your WordPress website using your web host’s File Manager or an FTP client.
- Remove the corrupted file and upload the fresh one from the installation package.
- Reload your website to see if this resolves the error.
For errors that originate from a theme or a plugin, reinstalling it is the easiest fix.
Alternatively, restore the WordPress site from a backup to address errors post-update. Hostinger users can follow these steps to restore a backup from the hPanel dashboard:
- Head to WordPress → Security from hPanel.
- Scroll down to the Update log section. Click on the three-dot menu next to the chosen backup version and select Restore.
- Wait until the restoration is complete, then reload your website.
If the issue persists, try reinstalling WordPress altogether to reset all the core files.
Pro Tip
Check out our WordPress debugging guide for tips and best practices to optimize your website’s functionality.
Conclusion
The “Cannot modify header information” error is a common occurrence among WordPress websites. It’s usually caused by accidental whitespace or premature output in PHP code.
If left unresolved, the WordPress header error can affect website performance and, ultimately, user experience. Luckily, the error message itself pinpoints the file that causes the issue.
To fix it, remove any blank lines or echo statements outside the PHP file’s opening and closing tags using a file manager or an FTP client. Alternatively, replace the faulty file, reinstall the extension or WordPress.
We hope this article will help you resolve the WordPress header error and get your website back up and running in no time. If you have any questions, take a look at our FAQ section or comment below.
“Cannot Modify Header Information – Headers Already Sent By” FAQ
This section answers some of the most common questions about the “Cannot Modify Header Information – Headers Already Sent By” error in WordPress.
How Can I Prevent the “Cannot Modify Header Information – Headers Already Sent By” Error?
To prevent the “Cannot modify header information” error, make sure there are no whitespace or unexpected echo or print statements before <?php or after ?> tags. Use tools like TextFixer and Code Beautify to remove whitespaces from your code. You should also prioritize well-coded plugins and themes.
How Can a Plugin Cause the “Cannot Modify Header Information – Headers Already Sent By” Error?
A plugin can cause the “Cannot modify header information” error if it generates output or whitespace before modifying HTTP headers. This often happens due to echo and print statements or coding mistakes, disrupting the header modifications for the site to function properly.
Can I Use Output Buffering to Address the “Cannot Modify Header Information – Headers Already Sent By” Error?
Yes, you can use output buffering to fix the error by wrapping your code with ob_start() at the beginning and ob_end_flush() at the end. This prevents the output from being printed immediately, allowing headers to load correctly.
Comments
April 10 2018
Great.Thanks.
August 17 2018
Great!!! problem solved by erasing blank spaces !!! Thank you so much!!!
November 29 2018
I absolutely love the way you explained this. The way you explain coding to a non-coder is just brilliant! It was well digested and I can't thank you enough.
January 30 2019
Great article. Helped me find and fix the problem on my WP site. Thank you!
February 27 2019
thanx alot its working
January 15 2020
Very helpful piece, a plugin had given headache for a week. Fixed it by deleting a fullstop at the beggining of <?php
January 29 2020
Happy to see that you fixed your plugin problem :)
March 06 2020
This Post Has Just Saved My Marriage ;) That "headers already sent" Error Was Sooo Annoying. Thank You Hostinger! (and Domantas G.)