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.

What Causes “Cannot Modify Header Information” Error?

In WordPress, 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 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

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.

Related tutorials


kamyar Reply

April 10 2018



Marcelo Reply

August 17 2018

Great!!! problem solved by erasing blank spaces !!! Thank you so much!!!


Crystal Reply

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.


mark Reply

January 30 2019

Great article. Helped me find and fix the problem on my WP site. Thank you!


saad Reply

February 27 2019

thanx alot its working


Samson Ogola Reply

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



    Replied on January 29 2020

    Happy to see that you fixed your plugin problem :)


Rehan Gillani Reply

March 06 2020

This Post Has Just Saved My Marriage ;) That "headers already sent" Error Was Sooo Annoying. Thank You Hostinger! (and Domantas G.)

Leave a reply




This site uses Akismet to reduce spam. Learn how your comment data is processed.

Become a part of Hostinger now!

More in WordPress
Become a WordPress Developer
How to Become a WordPress Developer