7 June 2022
You’d never run into a problem that required debugging in an ideal world. However, in the real world, you will almost certainly encounter problems with your WordPress site that require a look under the hood.
To help you do that, WordPress offers its own built-in debug mode, and you can also find handy third-party tools to help you debug WordPress.
In this post, we’ll explain what debug mode is and how to enable debug mode in WordPress using a plugin or manually.
Debugging is the process of checking and correcting errors in a piece of code.
When writing code, the developer makes mistakes, just as you would make spelling and grammatical errors when typing an email. Going back and fixing those errors is known as debugging in the coding world.
WordPress provides a simple way to debug bugs and errors caused by plugin and theme developers. However, debugging is turned off by default. You can enable it to fix issues like malfunctions and incompatibility. Let us show you how.
In WordPress, there are two ways to enable debug mode. Whatever method you use, keep in mind that you should always disable debug mode when you’ve finished troubleshooting.
WordPress debug mode will show PHP error codes on the front and back ends of your site, making them visible to visitors. Malicious hackers can take advantage of this information. Furthermore, it may cause users to be concerned about the safety of your website.
With that said, here are two methods to enable debug mode in WordPress.
If your web hosting service provider does not provide you with a specific link to enable WordPress to debug mode, you may always use WordPress plugins that help you enable debug mode. However, thousands of WordPress plugins are available, making it difficult for users to choose the perfect one.
As a result, for your convenience, we suggest that you use the WP Debugging plugin.
First, install and activate the WP Debugging plugin. For more in detail, see our guide on how to install a plugin in WordPress.
Upon activation, it will start working immediately. The plugin will set the following values to true in your wp-config.php file without your intervention:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'SCRIPT_DEBUG', true );
define( 'SAVEQUERIES', true );
All errors, notices, and warnings will be stored in a log, which you can view by clicking the Debug Quick Look link in your admin toolbar:
When you’re done debugging, deactivate the plugin to restore your website’s pre-existing constants.
You can also enable WordPress debug mode by adding a code snippet in your wp-config.php file. The sole reason to use this method is if you want to limit the number of WordPress plugins you have installed.
Note: Before you start editing your wp-config.php file, we strongly advise that you back up your website first.
There are so many backup plugins available, but the UpdraftPlus plugin allows you to upload your work to different cloud storage sites.
Once you’ve got a recent site backup, you can start editing your wp-config.php file.
Go and open the wp-config.php file and paste the following lines of code just before the line ‘/* That’s all, stop editing! Happy publishing. */’.
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true);
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true);
By following these steps, you’ll be able to enable debug mode and save your errors to a debug.log file.
Once you’ve finished with the debug mode, repeat the steps for enabling it, but this time remove or change the previously added code as follows:
// Disable WP_DEBUG mode
define( 'WP_DEBUG', false);
Apart from using WP DEBUG mode to find an error on your WordPress site, there are also some useful tips and tricks you may use to debug problems in Word Press.
For example, if your WordPress site crashes or displays a white screen of death. The most common debug solution for this problem is to disable your plugins and themes and check for updates. This method will help determine the actual cause of the problem, but it might be time-consuming. Furthermore, there’s a high possibility you won’t be able to detect the real issue.
As a result, you’ll need to use the correct tool to figure out what’s causing the error and fix it as soon as possible.
By enabling WPDP in your WordPress, you can also detect and identify any problems with the WordPress database. $show_errors is a variable in the $wpdb object that allows you to see all database errors. If you set this variable to true, all SQL errors will be displayed for any query.
var $show_errors = true; /** to show SQL/DB errors */
var $suppress_errors = false; /** to suppress errors during the DB bootstrapping. */
To activate WPDP error reporting, navigate to your public_html file and locate the wp-dp.php file within the wp-includes folder. Open the database file and look for the wpdb class to set the $show_errors variable to true.
Sometimes, you may encounter an internal server error page while browsing the website. The best thing you can do to fix this issue is to check your website’s complete error logs.
Simply reviewing your website’s complete error logs might be very helpful in identifying the likely culprit. If you do not know how to fix it after finding the likely culprit, a quick Google search will give you all available options.
WordPress uses CSS and javascript files to improve website performance and loading time. However, these javascript may contain hidden error codes that cause issues for your website.
So to eliminate such problems with script execution, WordPress provides you with a constant that you can add to your wp-config.php file.
Go and open the wp-config.php file and paste the following lines of code just before the line ‘/* That’s all, stop editing! Happy publishing. */’.
define('SCRIPT_DEBUG', true);
When the script debugs option is enabled, WordPress will use the full version of all plugins and the development version of CSS and javascript files instead of the compressed versions.
A staging platform, often known as an exact copy of your live website, is hosted on a subdomain of your website. This clone website will act as a testing and development platform, allowing you to add codes and run tests before launching the live version.
Furthermore, this staging site will not be visible to any of your website visitors, and search engines will also not be able to find it. As a result, it gives you a complete environment to conduct experiments with no limitations and without affecting your live website.
It is important to understand how to enable debug mode in WordPress. It can help you quickly solve common WordPress errors and identify the cause of a problem. Fortunately, this method does not have to be complicated, and you do not have to mess with your website’s code if you are not comfortable doing so.
You may also want to see our following articles:
Lastly, follow us on Twitter for regular updates on new articles.