One of the harder parts of error hunting in a WordPress site can be debugging the PHP code.
Fortunately, WordPress comes with specific debug systems that can simplify the process. The debug systems also standardize code across the core, plugins and themes.
I’ll describe describe some debugging tools in WordPress and how to implement them in your WordPress website. This will enable your awareness of errors.
If you are not a programmer, you can still benefit. These settings can be used to show detailed information about errors. Making your web hoster aware of the errors can help to reduce the costs involved with getting fixes implemented for them.
An Example of wp-config.php Code for Debugging
The wp-config.php file is the main configuration settings file for your WordPress website. Be very careful when editing it. I always suggest saving the original before editing – just in case. In this configuration file are important settings that allow the site to communicate with its database as well as other extremely important functions.
By inserting the following code in your wp-config.php file, you will be able to log all errors, notices, and warnings to a file called debug.log. In the code example here, that file will be placed in the wp-content directory. Most importantly, it will hide the errors so they do not interrupt page generation. Therefore, a sit can be live while you are debugging some of its functionality behind the scenes.
Be careful to place the debugging code before this line in your wp-config.php file:
/* That's all, stop editing! Happy blogging. */
Here is the code:
// This puts us in the WP_DEBUG mode: define( 'WP_DEBUG', true ); // This enables the debug logging directly to the /wp-content/debug.log file: define( 'WP_DEBUG_LOG', true ); // This disables the display of errors and warnings: define( 'WP_DEBUG_DISPLAY', false ); @ini_set( 'display_errors', 0 ); // This lets us use dev versions of core JS and CSS files and // is only needed if you are modifying these core files: define( 'SCRIPT_DEBUG', true );
Miscellaneous Notes About Logging
There is more to the WP_DEBUG_LOG constant than simply using true or false for its settings. You can use it to define where the log file is. Bear in mind that if you place it in any area of the website that is accessible from the web, anyone will be able to see it. Of course, they do have to know its path from the website’s root directory and they will need to know the file’s name. Also bear in mind that in the Linux environment (as opposed to a Windows environment), file and directory names are case sensitive.
For WP_DEBUG_LOG to function at all, WP_DEBUG must be enabled (true). You can turn the WP_DEBUG_DISPLAY one or off independently by setting it as true or false.
Here is an example of setting it:
define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );
Sources
Most of the information here was gleaned various parts of the WordPress.org site at the https://wordpress.org/support/article/debugging-in-wordpress/ page.