Debugging WordPress

WordPress allows you to alter the default settings in a way that is helpful for debugging problems … including problems you don’t know your site has.

The debugging process is best done on a development or local version of your site, where you can make changes without disrupting visitors to your site. Once you know what you need to do to fix the errors, you can then incorporate the changes into your live code base. Therefore, it pays to make note of what the existing code is and what changes you are making.

In the wp-config.php file, add these lines:

/* insert this ABOVE the line that reads "That's It. Pencils down" */
/* https://wordpress.org/support/article/debugging-in-wordpress/ */
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

// Saves database queries to an array that can be displayed to help analyze those queries
define( 'SAVEQUERIES', true );

If you want to see errors displayed on screen when you visit your site, add this code instead of the code above:

// Enable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', true );

One thought on “Debugging WordPress

Comments are closed.