WordPress is built with PHP and when things go wrong on your site seeing the PHP errors can help you to expedite your troubleshooting.
Good News! WordPress comes with a built-in tool to display PHP errors. The only problem is that it is sort of hidden and requires you to add a line of code to your wp-config.php file.
In this article, we will show you how to display and log WordPress errors.
How To Access Your wp-config.php File
To access your wp-config.php file, you will need log into your server using an FTP client like FileZilla. If you do not know your FTP credentials, your host's support will be able to provide them to you.
The wp-config.php file is stored in the WordPress install directory. After you open your enter your FTP credentials, you will be connected to your server. Now it is time to navigate to and open your wp-config.php file.
To edit the wp-config.php file, right-click the file and then select the View/Edit option.
Enabling PHP Errors in WordPress
What application is used to open the file will be dependent on how you configured your FTP client settings. I have set my FTP settings to use a text editor on my local machine to edit server files. Once you have the wp-config.php file open you will need to add the code below above the "/* That's all, stop editing! Happy blogging. */" line.
define('WP_DEBUG', true);
After you save your changes, PHP error will be displayed on your site. If you do not want the errors to display on your site, you can record them in a debug log.
How to Store Errors in a Log
To store the WordPress errors in a log, all you need to do is add another line of code to your wp-config.php file.
The first line you need to add is below.
define( 'WP_DEBUG_LOG', true );
What this will do is create a debug.log file in your site's wp-content directory, and the log will record all of the debugging errors.
How to Prevent Debug Errors Displaying on Your Site
When you enable the WP_DEBUG setting, the site errors will be visible when visiting the site from a browser. You can prevent the errors from being displayed by adding one more line of code to your wp-config.php file.
define( 'WP_DEBUG_DISPLAY', false );
How to Disable Debugging
You can disable the WordPress debugging setting by removing the code or by modifying the first line of shared in the article.
You will need to change
define('WP_DEBUG', true)
to
define('WP_DEBUG', false)
As you can see, I just changed true to false, which allows you to disable the WP_DEBUG while saving the code for quick enabling in the future.
While I hope you never run into any problems on your site, but if you do, now you will have another tool to use.