WordPress Error: Cannot modify header information – pluggable.php
I finished up some code on Friday and left for the weekend. Didn’t look at the site, didn’t look at the code, didn’t look at any of the commits. First thing Monday morning I’m told the site is broken. It’s a WordPress site, so a blank screen means any number of awful things have happened.
After a quick look at my debug file (generated by using this debug code) I saw this.
PHP Warning: Cannot modify header information - headers already sent by (output started at .../.../functions.php:1) in ../../wp-includes/pluggable.php on line 1179
So that at least narrows it down to the guilty file and guilty line.
Opening functions.php I didn’t see anything too suspicious. No broken code, no missing semicolons, PHP tags, nothing. Line 1, line 1. Hmmm.
I did a quick look in the WordPress support forums and it seemed unanimous that there was an extra space somewheres.
Taking a look at the repo on GitHub I found the jerk space. It was riiiiight before the opening PHP tag.
<?php // instead of this <?php
You got it, that small change was enough to bring down everything. Just goes to show that you need to be careful when copying code from around the web. Never know what small spaces might pop up.