WSOD for admin when using PHP 7

After a lot of testing and considerable frustration, I discovered the problem. I am including this solution in the hope that it saves someone else a lot of frustration if they encounter a similar problem.

The problem to be the presence of a PHP closing tag ‘?> ‘ in the functions.php file of the child-theme. It is not the closing tag itself that is the problem, but a blank line or even a space after the closing tag. This is sent to the browser as HTML and breaks WordPress because the header() function fails if anything is sent to the browser before this function is run. The redirect to the login page will not work and there is nothing to display (apart from the blank line or space) and hence the WSOD (White Screen of Death).

I guess I should have picked this up sooner, but as closing a php script using ‘?>’ is fairly standard practice, I am sure that may others may inadvertently also have a similar problem. It also is very curious that the closing tag on functions.php worked on a server with PHP 5.6 but not on a server with PHP 7. I accept that it may be some other setting on the server, but the best practice is simply not to use a closing tag in the functions.php file.

My advice is, check your functions.php and if you have a closing php
tag then remove it (even if it works right now) as the tag it is not
needed and can lead to problems that will be very difficult to
identify later.

Finally, below is my list of checks (in order) if you ever get a WSOD after moving or changing a WordPress installation:

  1. Check your functions.php file in your child theme and if there is a closing tag then delete is (it is not needed).
  2. Switch off all your plugins by renaming the plugins directory to something like pluginsX – check if this fixes the problem if this does then the error is in one of the plugins. Rename the directory back to what it was and then identify which plugin is the problem.
  3. Check memory limits allocated to PHP and increase these if necessary.
  4. If none of this works, rename the theme file – WordPress then will revert to the default theme twentysixteen.

After that, it should work because you are back to base WordPress functionality. However, if there still are problems then debug.

I hope that this helps and saves someone else a lot of time and a lot of frustration.

Leave a Comment