Cannot Modify Header Information

3 Ways to Fix WordPress “Cannot Modify Header Information – Headers Already Sent By” Error

WordPress is popular for being user-friendly and having an intuitive interface. However, technical issues in the platform can arise anytime. One problem you may encounter is the “cannot modify header information – headers already sent by” error. 

It usually happens when something is wrong with the code for your WordPress page header. We have found several ways to fix it! We will walk you through each method, so you know what to do.

What Are the Causes of the “Cannot Modify Header Information – Headers Already Sent By” Error?

When you encounter this error, there are two files involved that cause the problem. One file (my-function.php) is where the error originates that stops the other file (pluggable.php) from working properly. You will see the warning message 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 #

The line # code acts like a mark to help you see the faulty code easily and quickly. Also, other causes of the error include:

  • Extra blank spaces 
  • Incorrect configuration 
  • Typos
  • Header misplacement 

How to Fix the “Warning: Cannot Modify Header Information – Headers Already Sent By” Error

1. Edit the Corrupted File

If you see extra blank spaces in the corrupted file, you can fix it using your control panel. Log in to your control panel and go to File Manager under the Files section. 

cPanel File Manager

Open public_html and look for the wp-config.php file. 

wp-config.php

Open it by right clicking on it and selecting Edit from the dropdown. 

wp-config.php Dropdown

On the edit page, start looking at line # for the spaces. Remove the extra spaces you see in the file. 

The first line of the file should be the opening tag: <?php. Remove the extra space if you see one before it. Also, remove the spaces after the code’s last line and the closing tag ?>.

2. Replace the Faulty File 

If the cause of the “cannot modify header information – headers already sent by” error is from your theme or plugin, you can fix it by re-installing the theme or plugin. If the cause is with the core file in WordPress, replace it with clean code. Then, re-install your WordPress to automatically create a clean file.

3. Relocate Header Statement

In the coding system, your site’s header should be tagged first before the body. If you do not do this, it will create an error. To fix this, you need to look for the statement that delivers the output before the heading. Here is an example of an incorrect code:

<!-- wp:paragraph -->
<p>&lt;html&gt;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&lt;?php</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>header('Location: http://www.innzonehosting.com/');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>?&gt;</p>
<!-- /wp:paragraph -->

As you can see, the opening tag <?php is placed in the second line, which is incorrect. You need to move the <html> tag after the closing tag of the header: ?>. So, it will look something like this:

<!-- wp:paragraph -->
<p>&lt;?php</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>header('Location: http://www.innzonehosting.com/');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>?&gt;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&lt;html&gt;</p>
<!-- /wp:paragraph -->

Conclusion

Fixing the “cannot modify header information – headers already sent by” error is extremely easy. All you need to do is find out the cause of the problem first, so you know which method to use to resolve the issue. So, use our guide in fixing this error now and allow the proper function for your header again! 

About Us
Innzone Hosting offers superior, reliable and affordable Web Hosting to individuals and businesses worldwide.

© Innzone Hosting. All rights reserved.