Cannot Modify Header Information – Headers Already Sent By

When you are developing your WordPress website, an error message Cannot Modify Header Information – Headers Already Sent By appears and you don’t know what’s wrong. Don’t worry, because in today’s blog, we would like to show you the causes…

Cannot Modify Header Information - Headers Already Sent By

When you are developing your WordPress website, an error message Cannot Modify Header Information – Headers Already Sent By appears and you don’t know what’s wrong. Don’t worry, because in today’s blog, we would like to show you the causes of and solutions for this issue. Don’t miss it!

The reason for the error Cannot Modify Header Information – Headers Already Sent By

The error Cannot Modify Header Information – Headers Already Sent By is one of the most common errors in WordPress. As you know, WordPress is created based on PHP files such as wp-config.php and functions.php for the core functionality. So, if there is a problem in the code of a PHP file that prevents it from executing, you will get the error message below.

Cannot Modify Header Information – Headers Already Sent By 1

Some of the most common causes of the error include:

  • Before the <?php segment or after the closing ?> tag, there is whitespace.
  • Before the PHP header function, there is an HTML block.
  • Echo or print statements are added before the PHP header function.
  • Problems with an installed plugin’s code.

Now, it’s time for you to explore how to solve the issue based on the causes above and the line where the error occurs.

How to fix Cannot Modify Header Information – Headers Already Sent By

There are two basic solutions to deal with the error Cannot Modify Header Information – Headers Already Sent By. The first one is quite simple since you just need to make changes in the WordPress admin dashboard. Conversely, the second method requires you to make some adjustments to the problem file through FTP/SFTP. Now, let’s check out the first one!

Checking the problem file in Plugin/ Theme Editor

The first way to address the error Cannot Modify Header Information – Headers Already Sent By is to find the file and the code line causing the error. For example, the error is:

Warning: Cannot modify header information – headers already sent by (output started at /home/public_html/wp-content/themes/twentytwentyone/functions.php:#) in /home/public_html/wp-includes/file-example.php on line 1

As you can see, the error appears in the functions.php file of the Twenty Twenty-One theme, on line 1.

So, in order to solve it, you need to log in to your WordPress admin dashboard first. After that, go to Appearance -> Theme File Editor -> Theme Functions.

Cannot Modify Header Information – Headers Already Sent By 2

Now, you need to check and ensure that there is no whitespace before the <?php tag. If there is any whitespace before it, you need to remove the whitespace, then press the Update File button at the end of the page to save your changes. Finally, reload your website and the error should be gone.

You can implement the same process with the WordPress plugin editor. Simply go to Plugins -> Plugin Editor to do that.

Furthermore, sometimes, you may get the error because of a file in your WordPress plugin directory. In that case, you just need to delete and then install the plugin again. That should solve it.

Editing the problem file by using FTP/ SFTP

Sometimes, the error Cannot Modify Header Information – Headers Already Sent By is caused by a file that you can’t access directly in the WordPress theme or plugin editors. Thus, it’s a good idea to access the problem file via FTP/SFTP. Depending on the FTP client you are using, the way to reach the corrupted file will differ.

After opening the file that contains the error, try to find the code line mentioned in the error. Check the whitespace and remove it, then save the changes and close the FTP/SFTP client. Don’t forget to revisit your WordPress site to see the result.

Cannot Modify Header Information – Headers Already Sent By 3

Conclusion

In short, we have already given you 2 solutions to tackle the error Cannot Modify Header Information – Headers Already Sent By. We will be happy if you are able to fix the issue after following our guides. If you have any queries, please leave your comment below and we will answer you as soon as possible.

Last but not least, whenever you want to give your site a new look, don’t hesitate to visit our site and explore many well-designed free WordPress themes. We hope you enjoy the blog. See you in the next posts.

Build it with a template

Start from a finished design: Joomla templates, WordPress themes or the AI-ready block themes. Every template has a free version and a live demo.

Free download

We'll send the link, setup tips and update notices, and you can reach us anytime through our AI assistant and contact form.

The download starts at once. We email you the link and ask you to confirm your address. Privacy policy.