Whitespace … blank page … whiteout

By 10th May 2013August 24th, 2017Development

Hey, where did the page go? Suddenly your site is coming back blank and you can’t imagine why. Whiteout!

This happened to us recently to the wp-admin page of a WordPress site. It was part of a multisite network and the other sites all worked fine, so why did this one break?

First thing I checked was the page source … it was of course blank, but not quite. There were 3 lines of blank space. This is an important clue – PHP was sending back 3 lines of whitespace, not just simply sending nothing. As I’ve seen this error before I knew where to look, but I remember the first time I encountered it it was quite a mystery.

The cause was that a plugin was trying to change the HTTP headers, but the whitespace had already been sent which meant the code would fail and stop at that point. Where was the whitespace coming from? It’s after the closing ?> marker in the functions.php file for that site’s theme. The solution to this is to remove that closing marker – it’s not needed at all, and removing it guarantees that the whitespace at the end of your file will never be sent back to the client. It’s a common misconception that PHP needs that marker to work, but the manual advises against it.

Happy debugging!