HOW TO: Troubleshoot / Debug WordPress Error
Posted by Uvaraj N. on 10 January 2021 12:39 PM
WordPress includes several settings that you can use to help debug the main application, themes, your own custom code, and more.
Generally, these settings are intended for use by developers and should not be used on “live” sites. However, you can also use them in certain scenarios to help troubleshoot issues you may be experiencing with third-party code, such as plugins or themes.
To enable debugging mode in WordPress, follow these steps:
Additional debugging options
There are several additional settings you can use to control the debugging information that WordPress provides:
Logging database queries
If you are experiencing database issues with WordPress, you can enable query logging. When query logging is enabled, the following items are saved in the global $wpdb->queries array:
To enable database query logging, add the following line to the wp-config.php file:
Enabling this setting affects your site's performance. You should only enable this setting for as long as it is necessary to debug a problem, and then disable it.
The following PHP code snippet demonstrates how to dump the entire contents of the $wpdb->queries array to a page:
<?php global $wpdb; print_r( $wpdb->queries ); ?>
To view the official WordPress debugging documentation, please visit https://codex.wordpress.org/Debugging_in_WordPress.