How to Fix WordPress “Cannot Modify Header Information” Message

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.

Download All in One WordPress Cheat Sheet

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.

Example of an incorrect syntax that causes the "Cannot modify header information" error message

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:


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!

The author

Domantas G.

Domantas leads the content and SEO teams forward with fresh ideas and out of the box approaches. Armed with extensive SEO and marketing knowledge, he aims to spread the word of Hostinger to every corner of the world. During his free time, Domantas likes to hone his web development skills and travel to exotic places.