Need to find out how to fix the "Cannot modify header information" error?

Here is a common and frustrating WordPress error that can interrupt the execution of your website by displaying an error like:

Warning: Can not modify header information 

What is worse is that this error persists, listing the paths to important files on your server, which is a potential security risk.

But do not worry ! This is one of the easiest errors to fix and in this tutorial I will show you how to fix it as well as how to hide error messages on the frontend of your blog.

But before, if you have never installed WordPress discover How to Install a WordPress Blog in 7 Steps et How to search, install and activate a WordPress theme on your blog 

Then back to why we are here.

Probably a header problem?

Of course, this error may seem daunting and make you think there is a problem on the file " header.php Or something similar, but it's more of a space created in one of your files (usually before PHP's opening tags). Sometimes these spaces are added unintentionally or automatically and need to be adjusted.

Discover How to fix the "file_get_contents" error on a WordPress blog

The error manifests itself when there is:

  • Blank lines at the top or bottom of a document
  • Too many spaces before, between or after the beginning of the opening and closing php tags " <?php " and " ?> »
  • There are too many unnecessary spaces or blank lines in a specific part of a document

In order to fix the spacing issue, you first need to know where the spacing is. Fortunately, the error message lets you know which file and which line is affected. Keep in mind that you may see this sequence multiple times on the page which means there are multiple files that need to be fixed.

Here is the basic structure to look for to decipher the broken file:

Warning: Can not modify header information - headers already sent by (output started at /path/to/file/broken-file.php:#) in /path/to/file/affected-file.php on line # 

The first file listed as 

/path/to/file/broken-file.php

would be the one that needs to be corrected and the "#" character will be replaced by a number that will tell you which line to correct.

The second file written in this structure as

 /path/to/file/affected-file.php 

is the file that can not work properly because the first file is broken. The "#" symbol at the end in a real situation would be a number that indicates the line in the document that would be affected and therefore will not work. 

How to fix the "500 Internal Server" error on WordPress ? Discover by consulting this link.

Here is another example of what this error might look like on your website:

Warning: Can not modify header information - headers already sent by (output started at /home/name/your-site/wp-content/themes/your-theme/custom-functions.php:1) in / home / name / your- site / wp-includes / pluggable.php on line 876 

In this example, “name” will be the username of your cPanel or hosting account and “your-site” will be replaced with the name of the folder where your website is stored. The error you will see will certainly be different, but it should give you an idea of ​​what to do.

Learn by consulting this article How to fix an 504 error on your WordPress website

In this example, the file " custom-functions.php 'Within the' your theme 'folder is the document that needs to be fixed and the error is on one line.

Fortunately, this problem is not very difficult to resolve, although it can seem daunting at first.

Some solutions:

There are two main ways you can correct this error. If you are stuck during this fix, you are free to contact us, we are willing to help you. 

We also invite you to consult How to fix the "Can not write to disk" error on WordPress

Here is a list of solutions that you can put into practice

Fix # 1: Download a fresh copy

When you read the error message and determine that the offending file is a part of the WordPress core or is otherwise an inherent file of a plugin or theme, there is a quick fix available.

If this file is in a plugin or theme, you can uninstall it and reinstall it. 

Discover How to remove string v = xxx from WordPress URLs

If you'd rather not do this or if a WordPress core file is affected, you can download a fresh copy and extract the ZIP archive to your computer. Locate the offending file on your website and replace the existing one on your server with the new copy.

You can do this with the help of FTP, SSH or directly through the cPanel.

Fix # 2: Modification of the file in question

Once you have identified the file in question, you can download a copy of it by FTP or SSH, or you can edit it directly in the cPanel.

Erase any blank lines or extra spaces at the beginning and end of the document. Also, make sure there is no space before, between or after the " <?php At the beginning of the file. The same goes for the end tag " ?> ». 

If the last line of the document does not end with a "?>" Tag, make sure there is no space after the last line.

Save the file and transfer it to your website, overwriting the original file.

Disable error reporting

Now if you have fixed the problem, nothing will stop these errors from coming back and being visible to everyone who visits your website, including hackers.

There is nothing worse that can happen to your website because revealing the file paths on your server could give hackers the exact information they need to target your website or blog.

You can turn off front-end error reporting and enable a private log with WP_DEBUG. Check out the changes we recommend for your "wp-config.php" file.

Discover also some premium WordPress plugins  

You can use other WordPress plugins to give a modern appearance and to optimize the handling of your blog or website.

We offer you here some premium WordPress plugins that will help you do that.

1. WooCommerce Currency Switcher

The WooCommerce Currency Switcher plugin allows you to change currency and get the rates converted in real time (WooCommerce installation required beforehand). You can use currency aggregators to get converted rates either by Yahoo, Google, AppSpot aggregators, either manually.Woocommerce currency switcher

WooCommerce Currency Switcher is available as a widget and works in any space provided (shortcode available -> [woocs]). On the public interface, "Currency Switcher" can be presented in 5 different ways to discover.

Download | Demo | Web hosting

2. Ultimate Membership Pro

Ultimate Membership Pro is a great WordPress Plugin subscription and content restriction. It allows users to be managed according to their package (free or paid) by creating exclusive access levels.

Ultimate membership pro wordpress membership plugin

It will therefore be possible to protect all the content of your website, or just part of it. It will be for example a course, a lesson, a page, a product, a category, an image, etc ...

Its main features include: content protection, multiple levels of access, support for multiple payment gateways -PayPal, Authorize.net, Stripe, 2CheckOut, Bank Transfer-, partial content protection, and much more again…

Download | Demo | Web hosting 

3. W8 Contact Form

W8 Contact Form is one of the plugins of Contact form the most popular on WordPress. It offers a lot of features such as submission to multiple recipients, support for animations, unlimited form creation, different styles, and a wide variety of additional customization options.

W8 contact form wordpress contact form plugin

In addition, it gives your website or blog a professional system to make it easier to get in touch with your customers. You will be able to customize all of your forms according to your needs and your tastes.

Download | Demo | Web hosting

Other recommended resources

We also invite you to consult the resources below to go further in the grip and control of your website and blog.

Conclusion

Here ! That's it for this tutorial. We hope this will help you fix the "Cannot modify header information" error on WordPress. In eThis tutorial has been useful to you, we invite you to the share on your favorite social network.

However, you will also be able to consult our resources, if you need more elements to carry out your projects of creation of Internet sites, by consulting our guide on the WordPress blog creation.

Tell us about your Comments and suggestions in the dedicated section.

...