If you are a WordPress developer you will definitely find this article of great use. Debugging in WordPress comes in handy each time you get in trouble. There are several ways to debug an error in WordPress, so check the list below.
1. Enable WP_DEBUG mode in WordPress
WP_DEBUG is one of the most used methods of debugging in WordPress. WP_DEBUG is a global variable meant to show you PHP errors on the front-end of your WordPress website. By default, it is set to false, but you can activate it in your wp-config.php file by defining it as true.
//Enable WP_DEBUG mode define ( 'WP_DEBUG' , true );
Now you can check your website and if any errors are being generated, they will be displayed at the top of your page.
2. Enable WP_DEBUG_LOG mode in WordPress
If you want to have the errors generated by WP_DEBUG saved in a log for later analysis you need to activate the WP_DEBUG_LOG variable. To do this place the below code in the wp-config.php file. A log file called debug.log will be generated in your /wp-content/ directory.
//Enable WP_DEBUG_LOG mode define ( 'WP_DEBUG_LOG' , true );
3. Use SCRIPT_DEBUG for debugging in WordPress
//Enable SCRIPT_DEBUG mode define ( 'SCRIPT_DEBUG' , true );
4. Query analysis with SAVEQUERIES
If you want to see how long each query needs to be executed and which function called it you can use SAVEQUERIES. This will save all queries in an array that can be displayed for further analysis.
//Enable SAVEQUERIES mode define ( 'SAVEQUERIES' , true );
Note: The array is stored in the global $wpdb->queries. Make sure to have this set on false when debugging is not needed as this will have an impact on your website performance.
Tip: Other interesting WordPress related articles you might find interesting and helpful:
- What is a WordPress child theme, how to create and use it
- How to create One Page menu in WordPress
- How to translate a website or a plugin in WordPress