WordPress comes with a special debug system (WP_DEBUG_LOG & WP_DEBUG) designed to simplify the debugging process throughout the core, plugins, and themes while standardizing code across them.
Whenever WordPress debug is enabled, it will log any errors found on your site. You can use this to figure out the source of a problem or to learn more details about potential errors on your site.
The debug mode of WordPress can be activated in the wp-config.php file through the activation of the WP_DEBUG_LOG and WP_DEBUG_DISPLAY constants.
In this article, we’ll tell you all you should know about these two WordPress constants, and also when to use SCRIPT_DEBUG and SAVEQUERIES, so you can have all the information you need to troubleshoot WordPress sites.
Table of contents
Add these 5 lines of code to your WP-Config.php file to fully enable WordPress debug mode.
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false ); define( 'SCRIPT_DEBUG', true ); define( 'SAVEQUERIES', true );
WP_DEBUG is a PHP constant that enables the “debug” mode in WordPress. By default, WP Debug should be set FALSE so hackers can’t get access to precious information about your website health.
This means that WP_DEBUG should only be set TRUE when you are debugging a website or on local testing and staging installs. Using WP_DEBUG on a live site is not recommended.
You can change the value of WP_DEBUG in the wp-config.php file.
define( 'WP_DEBUG', true );
When WP_DEBUG is enabled, all PHP errors, notices, and warnings will be displayed.
If you show all PHP notices and warnings, you may get error messages for things that appear to work, but do not follow PHP’s data validation conventions.
Getting rid of these warnings is easy once the relevant code has been identified, and the resulting code is almost always more bug-resistant and easier to maintain.
Working code, happy customers!
The WP_DEBUG_LOG constant enhance WP_DEBUG by logging all errors to a debug.log file. It’s useful if you need to review all notices later or want to view notices that are generated off-screen (for example, during an AJAX request).
By default, the debug.log file is saved in the content directory (generally wp-content/debug.log) of your website.
If you want to record your PHP errors in another file, you can do so by adding this lines of code in your config file:
define( 'WP_DEBUG_LOG', true ); -or- define( 'WP_DEBUG_LOG', '/yourpath/wp-errors.log' );
To function, WP_DEBUG_LOG needs WP_DEBUG to be set true.
WP_DEBUG_DISPLAY controls whether debug messages are displayed inside the HTML of pages or not and is an extension to WP_DEBUG.
When set to true, errors and warnings will appear as they are generated. By setting this to false, all errors will be hidden.
WP_DEBUG_LOG should be used in conjunction with this so errors can be analyzed later.
The functionality will help you test modifications to .css or .js files.
By default, the value of SCRIPT_DEBUG is false.
By using the SAVEQUERIES definition, database queries are saved in an array, which can then be displayed to assist with analyzing them.
By setting the constant to true, each query is saved with the number of seconds it took to execute, as well as the function that called it.
If you feel overwhelmed about enabling WordPress debugging yourself, there are a couple of plugins that you can use to do it. The two most famous are WP Umbrella and Query Monitor.
To enable PHP errors monitoring you only need to download, install and activate WP Umbrella on your WordPress website.
Your PHP errors will be monitored and stored in WP Umbrella’s dashboard with all the information you need to know about so you can troubleshoot them easily.
In addition to PHP error monitoring, WP Umbrella also offers daily automatic backup, uptime monitoring, and much more.
Query Monitor is a free plugin that helps webmasters analyze page requests on the frontend and backend. Besides giving you many useful reports, it also tells you about critical PHP issues.
A new toolbar item will appear once you have installed and enabled it. Whenever a critical (PHP) error is detected, a red warning appears.
Query Monitor has a drawback: it does not monitor or log PHP errors. You need to browse your website and find the errors yourself so we would recommend you to use WP Umbrella or the WP_DEBUG constants.
We hope this article has helped you to enable WordPress debugging mode and that you’ve understood how WP_DEBUG & WP_DEBUG_LOG work!
Everything you need to know about the wp-config.php file in WordPress.
Learn how to update WordPress themes like a pro.
Tutorial explaining how to update WordPress core safely so you don’t break your website.