Feb 14, 2023
How to Fix WordPress “Cannot Modify Header Information” Message
If you encountered WordPress “Cannot modify header information” error, that means there’s something wrong with your website’s page header code. Not to worry — we’re here to help! In this article, we will discuss why this error occurs in the first place and how to fix the issue in no time.
What Causes “Cannot Modify Header Information” Error?
In WordPress CMS, this error occurs when there’s a faulty code in your page header. For example, the message will look similar to this:
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 #
Two files are usually mentioned and the source of the problem originates from the first one which prevents the other from functioning properly. Meanwhile, line # indicates the location of the faulty code, which helps you locate the issue without having to scour the file manually.
In most cases, having extra blank spaces (whitespaces) or sending the output before calling the header first causes the error. With the help of the information in the error message, you should be able to solve this issue in no time.
Fixing “Cannot Modify Header Information” Error
Typos, incorrect software configuration, and header misplacement are some of the most common causes of this error.
Here’s how to troubleshoot WordPress “Cannot modify header information” message:
1. Editing Corrupted Files
If the faulty file has whitespaces, the easiest way to solve the issue is to manually edit the issue via an FTP client like FileZilla or a File Manager. You can start from line # mentioned in the error message, then look through the rest of the file for any unnecessary spaces.
Make sure to pay attention to the beginning and end of PHP tags. There should be no spaces before the <?php tag or after the closing ?> tag and file’s last line of the code.
Most text editors can remove whitespaces automatically. Alternatively, you can use online whitespace removal tools like TextFixer and Code Beautify to do the job for you.
2. Replacing Corrupted Files
If the “Cannot modify header information” error originates from a plugin or theme, you can easily solve it by re-installing the software. If it’s a WordPress core file, your best solution is to replace the faulty file with a clean version and reboot the website. The new installation will generate the proper file automatically.
3. Relocating Header Statement
By default, the header must be called first before sending any output from the body. Sending output before calling the header, including having unparsed HTML sections in the PHP file, likely causes the error. Here’s what an incorrect code will look like:
<html> <?php header('Location: http://www.hostinger.com/'); ?>
To solve this issue, you need to find the statements that send output above the header. Then, move the header statement on top of the faulty statement and make any necessary modifications to the code accordingly.
Whether you pasted a code snippet to your file, installed a new plugin or theme, or write the code manually, you risking adding extra blank spaces to the file. If you’re not careful, these might trigger the “Cannot modify header information” error.
Did you find our tutorial helpful in solving this WordPress error? Let us know in the comments section below!
Check out the following tutorials to find out how to fix other WordPress issues:
How to Debug WordPress
How to Fix WordPress Not Sending Emails
How to Fix Locked Out of WordPress Admin
How to Fix WordPress White Screen of Death
How to Find and Fix Broken Links in WordPress
How to Fix Error Establishing a Database Connection
April 10 2018
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.)