WordPress has a special debug mode that can be used to log error messages of the server-side scripting language PHP, in which much of the WordPress logic is programmed.
By default the mode is not activated and this is a fine, because it should only be switched on for troubleshooting and then switched off again.
Activating the WordPress Debug Mode
Editing file wp-config.php
To activate the debug mode, open your configuration file wp-config.php in the root directory of your site in a text editor. Scroll down to this line:
define('WP_DEBUG', false);
The false
means that the mode is not activated.
Replace this line with the following:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Explanation
WP_DEBUG
Setting WP_DEBUG to true
switches the mode on in general. Important in this context are the two new values.
WP_DEBUG_LOG
If set to true
, WP_DEBUG_LOG ensures that any error messages that occur are logged in a server-side file. The file is created in the wp-content
directory of your site with the default name debug.log
. So make sure that this directory is writable for the PHP process or create the file manually and give it write permission (664).
WP_DEBUG_DISPLAY
For a productive site it is very important to set the third value WP_DEBUG_DISPLAY to false
, because it ensures that the error messages are not displayed in the frontend of your site.
More details about how debugging in WordPress works can be found on the official WordPress developer page Debugging in WordPress.
Deactivating the Debug Mode
When the debugging is finished, it is important to switch off the debug mode again. Otherwise the log file would continue to be bloated with unnecessary entries. To switch off the WordPress debug mode, set the value WP_DEBUG
back to false
as in the initial state.
define('WP_DEBUG', false);
Short URL: https://bit.ly/asa2-wp-debug-mode
Check out more WordPress Tutorials