View PHP errors in WordPress by enabling wp-debug mode

WordPress is a PHP based Content Management System (CMS). It's likely that at some point you'll need to fault-find a PHP error. The most common of these is the white-screen - where your site simply outputs a blank white screen.

There are a number of places to look for information that might help you pin-point what's causing the problem. This includes the PHP and error_log files.

WordPress also has a PHP debug option that can be set within your wp-config.php file - normally found in the web root directory of your site.

Edit wp-config.php and find the following line - it will normally be set to false and should never be set to true on a live site unless you are fixing an error - after which it should be set back to false again:

define( 'WP_DEBUG', false );

To turn on PHP error display change this line to:

define( 'WP_DEBUG', true );

Any PHP errors will now be displayed when you view the site.

If the WP_DEBUG line doesn't exist you can add it anywhere above the /* That's all, stop editing! Happy blogging. */ line.

There are other options you can set to do things like turn debugging on - but write errors to a file instead of to the screen. In the following example setting WP_DEBUG_LOG to true causes the errors to be written to wp-content/debug.log.

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'SCRIPT_DEBUG', true );

Additional options can be found in this WordPress.org article - Debugging in WordPress (external link opens in a new window).


How did we do?


Powered by HelpDocs (opens in a new tab)
© Krystal Hosting Ltd 2002–