PHP whitespace: Headers already sent

In this example, you will download the attached zip file and activate it.

Download Zip

Expected Outcome Expected Outcome

Once activated, you should see the following error on your screen:

Screen Shot showing error message

This time you may not see any other errors!

Top ↑

How to fix How to fix

If you haven’t already, turn on debug by editing your wp-config.php file and changing the WP_DEBUG define to true: define('WP_DEBUG', true);

Now you should have an error like the following at the bottom of your Admin Dashboard:

Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /Applications/MAMP/htdocs/wordpress/wp-includes/functions.php on line 2732

or this at the top:

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/wordpress/wp-content/plugins/twitter-profile-field/twitter-profile-field.php:28) in /Applications/MAMP/htdocs/wordpress/wp-includes/option.php on line 571

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/wordpress/wp-content/plugins/twitter-profile-field/twitter-profile-field.php:28) in /Applications/MAMP/htdocs/wordpress/wp-includes/option.php on line 572

The actual line numbers may vary based on your install. The important information is the part that mentions the plugin: plugins/twitter-profile-field/twitter-profile-field.php:28

If you open that file in a code editor on your computer, you’ll see there are extra lines after the closing PHP tag:

Screen Shot showing added extra lines

Once you remove these extra lines, the error will go away. In this case, it’s easiest to remove the trailing PHP tag:

Screen Shot showing just a closing bracket

WordPress does not require the closing PHP tag.