The “Cannot modify header information…” WordPress Error

You are working away at building your WordPress website. Having fun finding plugins to add exciting new functionality to your site when error messages start appearing at the top of the WordPress admin.

The error message starts with (1) “Warning: Cannot modify header information – headers already sent by…”, followed by (2) a reference to a plugin file and (3) a reference to “pluggable.php on line 850”.

This error can seem like a bunch of gibberish, but once you know what you are looking for, it is quite easy to fix.

The Source of the Error

What has happened is that a PHP file in a plugin folder has picked up an extra line or two after the closing PHP tag. Sounds complex, but it isn’t.

Basically, WordPress doesn’t want to see any extra lines after the “?>”. The page should end immediately afterward. Doesn’t seem like a big detail, but coding is about little details.

Finding the Guilty Plugin

Section (2) in the above diagram tells you the plugin with the frivolous carriage returns.

You will recognize the “/wp-content/plugins/” as the folder that you uploaded your plugins into. After that is the name of the plugin folder with the corrupt file. In this example, it is WP-Print (an excellent way to add printer friendly pages to your website).

The Fix

The easiest fix is to download a fresh copy of the plugin and replace it for the old folder.

If you have customized the plugin, replacing the entire folder may mean losing your modifications. In that case:

  • Find the file identified in section (2) of our diagram. In the example, that would be wp-print.php in the wp-print folder.
  • Open that file in the WordPress plugin editor or your favorite code editor.
  • Place your cursor right after the “?>” at the bottom of the file and hit the delete key on your keyboard until no additional spaces remain.