Setting Up WordPress Debug

Setting Up WordPress Debug

When something breaks on your site and you are not sure of the cause turning on WordPress Debug can help narrow it down.

First, you should not show warnings, errors, and notices on a live site. If you have to use it on a live site, use it only for the time needed to resolve the issue and then turn it back off.

Second, you will need access to your wp-config.php to add the constants. Add them above this line:

/* That's all, stop editing! Happy blogging. */

Turn On WordPress Debug

To turn on error messages change the following to true:

define( 'WP_DEBUG', true );

This will display all PHP warnings, notices, and errors directly in the page source.

This can cause more problems such as headers already, so, it is a good idea to log all the errors in a file.

To do that add the following constants:

define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set('display_errors', 0);

Now all errors will be logged into the debug.log file found in your /wp-contents/ directory.

Your final coding will look like this for debugging PHP errors:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set('display_errors', 0);

Script Debug

You may find it useful to debug scripts and styles on your WordPress install, but by default WordPress loads the minified version.

Add this constant to load the full version of the files for easier debugging:

define( 'SCRIPT_DEBUG', true );

Looking for more help on debugging? Check out the WordPress Codex.

More Debugging Information

If you are looking for more in depth debugging and performance information beyond these methods. The Query Monitor Plugin is a great resource to have on all your development sites.