How to enable debug log on a WordPress website?

Be it theme / plugin development or inspecting WordPress site for malware cleanup, WordPress debugging tools come in handy for identifying the potential issues. WordPress in debug mode helps in detecting errors, notices, and warnings which can be an underlying source of an issue or can be used for learning more details about any possible errors on your site.

Here are various PHP constants (permanent global variables) defined in WordPress for activating debug mode:


WP_DEBUG PHP constant is used to turn the debug mode on. When the debug mode is on it will display all PHP errors, notices and warnings including notices about deprecated functions and arguments within WordPress that are being used on your site. It is assumed to be false by default and is usually set to true in the wp-config.php file for development or debugging purposes.

// This enables debugging.
define( 'WP_DEBUG', true );
// This disables debugging.
define( 'WP_DEBUG', false );

Once done with inspecting / debugging, don’t forget to turn the debug mode off!


By default when the debug mode is enabled, it displays all the errors, notices and warnings on the front-end. With WP_DEBUG_LOG enabled we can causes all errors to also be saved to a log file. This comes in handy for reviewing all notices later or to view notices generated off-screen (e.g. during an AJAX request or wp-cron run).

// Enable Debug logging
define( 'WP_DEBUG_LOG', true );

When WP_DEBUG_LOG is set to true, the log is saved to debug.log in the content directory at the following location: wp-content/debug.log. Alternatively, you can also specify a valid file path if you want to save the file elsewhere.

// Enable Debug logging and specifying the location for the log file
define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );


WP_DEBUG_DISPLAY is used to control whether debug messages are shown on site’s front-end or not. The default value is true which shows errors and warnings on the front-end as they are generated.

You can set WP_DEBUG_DISPLAY false to hide all the errors. This should be used in conjunction with WP_DEBUG_LOG so that errors can be reviewed later.

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

Enabling Debug Logs

Here is the complete code to enable debug logs. Edit your site’s wp-config.php file and replace define( ‘WP_DEBUG’, false ); with the following:

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging, the file is save 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 );

Once errors are generated, a debug.log file site will be generated in wp-content folder. This file can be accessed via FTP / sFTP.

Other debugging constants

SCRIPT_DEBUG: This constant forces WordPress to use the “dev” versions of core CSS and JavaScript files rather than the minified versions that are normally loaded. This is useful when you are testing modifications to any built-in .js or .css files. The default value is false.

// Enable script debugging
define( 'SCRIPT_DEBUG', true );

SAVEQUERIES: This constant saves the database queries to an array (in the global $wpdb->queries) and that array can be displayed to help analyze those queries. When the value of the constant is set to true it causes each query to be saved and display how long that query took to execute, and what function called it.

// Enable Save Queries
define( 'SAVEQUERIES', true );

This will have a performance impact on the site, so make sure to turn this off when you are not debugging.

Additional Resources: