Fix “Warning: cannot modify header information – headers already sent by”

If you have encountered the WordPress error «Warning: cannot modify header information – headers already sent by“, that means there is something wrong with the header code of your website page. Don’t worry, we are here to help you. In this article, we will explain why this error occurs and how to fix it in no time.

Why I get the error ‘Cannot modify header information – headers already sent by’

In WordPress, this error occurs when there is faulty code in your page header. For example, the message will look something like 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 #

Normally two files are mentioned and the source of the problem comes from the first one, which prevents the other one from working correctly. Meanwhile, the # line indicates the location of the faulty code, helping you locate the problem without having to walk through the file manually.

In most cases, the existence of extra whitespace 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 resolve this issue in no time.

Fix ‘Cannot modify header information – headers already sent by’

Typos, incorrect software configuration, and poor header placement are some of the most common causes of this error.

Here’s how to fix the WordPress message «Warning: cannot modify header information – headers already sent by«:

1. Edit damaged files

If the faulty file has whitespace, the easiest way to fix the problem is to manually edit it through a File Manager. You can start from line # mentioned in the error message, and then search the rest of the file for any unnecessary spaces.

See also  What is PHP? Learn all about the scripting language

Make sure to pay special attention to the beginning and end of PHP tags. There should be no spaces before the tag or after tag ?> and from the last line of code.

Many text editors can remove white space automatically. Alternatively, you can use online whitespace correction tools like and to do the work for you.

2. Replace damaged files

If the error «Warning: cannot modify header information – headers already sent by» originates from a plugin or theme, you can easily fix it by reinstalling the software. If it is a WordPress core file, the best solution is to replace the faulty file with a new version and restart the website. The new installation will generate the appropriate file automatically.

3. Relocate the header statement

By default, the header must be called first before sending any output from the body. Sending an output before calling the header, including having unparsed HTML sections in the PHP file, is likely to cause the error. This is what bad code looks like:

To solve this problem, you must find the statements that send the output above the header. Then, move the header statement above the faulty statement and make any necessary code modifications accordingly.

conclusion

Whether you paste a code snippet into your file, insert a new plugin/template, or write code manually, you run the risk of adding extra whitespace to the file. If you are careless, this can trigger the error «Warning: cannot modify header information – headers already sent by«.

See also  How to make an effective landing page

Did you find our tutorial helpful in solving this WordPress error? Let us know in the comments section below.

Gustavo is passionate about creating websites. He focuses on the application of SEO strategies at for Spain and Latin America, as well as the creation of high-level content. When he is not applying new WordPress tricks you can find him playing the guitar, traveling or taking an online course.

Loading Facebook Comments ...
Loading Disqus Comments ...