Sometimes we are unable to reproduce a problem that a user is encountering when using one of our WordPress plugins. When this happens, we ask the user to send us more information about their website’s and plugin’s setup.
Such information is typically found in a log file, more specifically, the WordPress debug log file. This log file can be generated by enabling the WordPress debug mode. In this post, we’ll dig into the built-in WordPress debug mode and show you how to enable it. Then, we’ll also share some additional WordPress debugging options.
Here’s what we’ll cover:
- Introduction to WordPress debug mode
- How to enable WordPress debug mode
- Additional WordPress debugging options
- Does WordPress debug mode affect the performance of your website
What’s the purpose of WordPress debug?
In case of present issues on your website, the WordPress debug mode can help you discover what is going wrong on your website. It does so by reporting all errors, warnings and notices. All of these are shown in the UI and can also be redirected to a log file.
Note that debugging is disabled by default on WordPress and it should only be enabled temporarily to troubleshoot issues. WordPress debug should not be permanently enabled on live websites because it will affect the performance of the plugin and possibly disclose sensitive information about the website that can be used maliciously.
Enabling WordPress debugging
To enable the WordPress debug mode and the debug log file follow the below procedure:
- Enable WordPress debug by setting the WP_DEBUG switch in the wp-config.php file to true, as per the following example: define( ‘WP_DEBUG’, true );
- Enable the debug log file by adding the following line to the wp-config.php file: define( ‘WP_DEBUG_LOG’, true );
The WordPress debug log file is called debug.log and it is created in the /wp-content/ WordPress subdirectory.
Once you enable debugging, reproduce the issue so the error is captured in the log file. After you reproduce the issue, disable the debugging by setting both the WP_DEBUG and WP_DEBUG_LOG directives in the wp-config.php file to false, as per the below:
Additional WordPress debugging options
Most probably we will never ask you to use these options, but it is good to know about them as well. Apart from the above mentioned ways to debug, you can also use the following WordPress debugging methods:
When this option is enabled alongside the WordPress debug switch, WordPress shows the debug messages in the HTML pages as they are generated.
Note that if this is used on a live website this could lead to the disclosure of sensitive information about the website and server setup. To enable this option, add the below line to your wp-config.php file:
define( ‘WP_DEBUG_DISPLAY’, true );
This debugging option is useful if you are testing changes in .js and .css files. To enable this option add the below line to your wp-config.php file:
define( ‘SCRIPT_DEBUG’, true );
Logging of WordPress database queries
On WordPress, you can also keep a log of the WordPress database query in an array. This option comes in handy if you are experiencing WordPress database issues, or you want to check what queries are being sent.
To enable it, add the following line to your WordPress wp-config.php file:
Once you enable this option all queries will be saved in the $wpdb->queries global.
Does debugging affect the performance of my WordPress website?
Yes. Some debugging options can have an impact on the performance of your website. Therefore, unless it is a test or staging website, or you’re instructed to temporarily enable debug by developers do not enable debugging on live websites.