Enabling WP_DEBUG

When it comes to programming, its safe to say that no developer is perfect – you will write code that throws errors, and when you do you’ll need to know why. Even even the simplest syntax errors in WordPress theme code can give you a result that’s not particularly helpful – either the dreaded white-screen (no output), or a browser friendly error (friendly to website visitors, but certainly not developers). Consider the following code:

Example 1: A tiny mistake

Okay, you’re looking for an error, so you’ve probably spotted the mistake here fairly quickly – but dropping a semi-colon is a very easy thing to do. Unfortunately, this tiny error will either give us a “white screen” (absolutely no output), or a “friendly” error like this Chrome page:

If this is the only PHP code on your page, or you’ve only just added these 5 lines of code since last refreshing the browser, this might be easy to spot and fix. But if you’ve just written hundreds of lines of code including this error since you last refreshed, it could be far more difficult to discover the source of the problem.

The first thing you can do in this scenario is enable “WP_DEBUG” in your wp-config.php (WordPress configuration) file, by adding this line:

Example 2: The WP_DEBUG definition in wp-config.php

Now when you access the page with this code again, you’ll get something like this (you may also get other errors and warnings, but this would be in there somewhere):

Parse error: parse error, expecting `','' or `';'' in /path/to/your/site/wp-content/themes/my-theme/single.php on line 6

Much better – now you can quickly fix the error and move on. Enabling WP_DEBUG should often be your first port of call when you get a white-screen or friendly error.

Note that you should ensure WP_DEBUG is disabled on any production servers, or site visitors may see strange warnings and error messages. You can do this by either commenting this line of code out, or defining WP_DEBUG as false:

Example 3: Disabling WP_DEBUG

Latest From the Blog

MasterPress 1.3.10 is now available

9th November 2023

MasterPress 1.3.10 is a feature and bugfix release. Workaround for fatal error introduced by changes to WordPress’ wpdb class in WordPress 6.4. Added actions to MPC files upload_field & WF image save_image functions.

Plugin Requirements

MasterPress requires a minimum of WordPress version 4.9, MySQL 5.6, and PHP version 5.6.20.

We also recommend that PHP is configured to use a memory limit of 64MB per request (128MB may be required for sites with higher complexity).

This plug-in is not compatible with the WordPress.com hosted service.

Three AM