In the dynamic world of website development, ensuring that your WordPress site functions flawlessly is of paramount importance.
WordPress Debug Mode is a valuable tool that can help developers identify and troubleshoot issues effectively.
In this article, we will delve into the intricacies of WordPress Debug Mode, and how you can use it to enhance your website’s performance.
Table of Contents
what is WordPress Debug Mode?
WordPress Debug Mode is a built-in feature that allows developers to identify and rectify errors and issues within their WordPress websites. It provides valuable insights into what’s happening behind the scenes, helping developers track down and fix problems that may not be immediately visible on the front end.
What Is Debugging Log?
The debugging log is useful mainly if you need to review all notices at a later time. You can also view notifications generated off-screen by accessing the debug.log log file.
This debug.log log file can be viewed from your website’s content directory.
Additionally, the debugging log is a file storage system where all the errors in a website are collected and stored to be worked on.
In the case of a WordPress website, the WP_DEBUG_LOG tool is used to collect all the errors in the website. These errors are then stored in the debug.log log file.
How to enable WordPress debug mode using WP_DEBUG.
Enabling your WP_DEBUG to debug errors is one of the easiest ways to log a problem on a WordPress site.
The WP_DEBUG is a PHP constant in the WordPress site that triggers the DEBUG mode in the site. It can be found in the wp-config.php file.
Below are steps to enabling your WordPress website’s debug mode using the WP_DEBUG:
1. The WP_DEBUG is always set to false by default and is located near the file’s bottom.
2. your server through FTP or SSH depending on the one you choose. This article will cover the use of FTP so you will need to install the FileZilla FTP client on your computer.
3. Input your access data to FileZilla’s site manager.
4. Locate the wp-config.php file from your website’s public_html folder.
5. Download the file copy to your computer.
6. To edit the contents of the file, you will need a code editor. You can use the Visual Studio code editor or Sublime.
Define (‘WP_DEBUG’, false);
Change the default setting from false to true
Define (‘WP_DEBUG’, true);
and also change the WP-DEBUG_LOG to true as shown below;
Define (‘WP_DEBUG_LOG’, true);
7. After the modification of the file, you will need to upload the file back to the server using the FileZilla FTP client to replace the original file with the modified one.
If you carefully follow the steps above, then you will successfully activate the WP_DEBUG mode. And also the WP_DEBUG_LOG will then create a debug.log file where all the errors collected from your website will be stored.
Other Ways to Debug Problems in WordPress
Enabling Script Debug Using Script_debug.
WordPress by default comes with a small version of CSS and Javascript to help enhance a website’s load time.
However, this can be a little tasking as some errors tend to hide between scripts and plugins that the website is using.
To enable the script debug, however, you will need to repeat the step above to change the script’s execution from false to true. From the wp-config.php, there is a constant that has been produced by WordPress which when enabled tackles the issue of errors hiding in scripts or plugins, that is:
define(‘SCRIPT_DEBUG’, true);
By setting SCRIPT_DEBUG to true, WordPress will load the non-minified CSS and Javascript files automatically.
This makes all the plugins on the site use their full versions.
Enabling/Disabling Display Errors Using Wp_debug_display.
Enabling the screen display forces a website’s errors to appear on the front end of the website
Also, enabling the screen display makes the front end of a website stuffy and unorganized. See the image below;
However, if the site is still in development you can choose to enable the WP_DEBUG_DISPLAY so that errors and PHP notices may be shown on the front end of the website.
But if the website is fully functional and is on a live server, it is advised to disable the WP_DEBUG_DISPLAY as it makes the front end stuffy and unorganized.
Enabling the debug mode by default enables the display and sets it to true. However, you should disable it as it may give away important information about your site, which you wouldn’t want.
You can access the WP_DEBUG_DISPLAY by repeating the steps we took initially and adding the code below to your wp-config.php file.
define(‘WP_DEBUG_DISPLAY’, false) ;
Enabling/Disabling Database Query Log.
Queries are important in WordPress because they locate data from the MySQL database.
See also: wordpress.com vs wordpress.org
Installing WordPress on a local host
Whenever a user views a WordPress page, MySQL queries running in the background fetch data from the database which are then used to generate HTML files for your browser.
Debugging issues that have to do with queries can be difficult. You might want to observe which database query is working at a particular time.
Also contained in the wp-config.php file is a constant that allows you to log all the queries that are currently running on your website.
Enabling the database query log makes it easier to access which database query is running. Especially if you are performing a performance check or troubleshooting.
From the wp-config.php file, add the wp-config below to enable the database query log for your site.
define(‘SAVEQUERIES’, true);
Enabling this will cause all your queries to be stored in the $wpdb->queries global.
Using Other Debugging Tools
Free WordPress Debugging Plugin From Andy Fragen
Andy Fragen is the creator of the free WP-debugging plugin. It helps tackle the issue of errors in a website.
Also, with the WP-debugging plugin you can enable your website debug mode with ease and without complications. All you need to do is download and install the plugin, as seen in the image below.
After installing the plugin activate it after which you will navigate the dashboard and locate the tools section. Click on the tools to expose its content. Navigate to the wp debugging option and click.
It provides ease in accessing the wp-config.php file. After activation, the plugin sets the constants below in the wp-config.php and tends to remove them when the plugin is deactivated.
Default settings:
for WP_DEBUG_LOG,
define( ‘WP_DEBUG_LOG’, true );
and for SCRIPT_DEBUG.
define( ‘SCRIPT_DEBUG’, true );
lastly, for SAVE QUERY,
define( ‘SAVEQUERIES’, true );
There is a list of settings that you can choose from as you can see from the picture above. To enable the WP_DEBUG, click on the check box next to the ‘set WP_DEBUG to true. Do the same for other options.
You can also use this plugin to have a quick look at the debug.log file. You can do this by clicking on the debug quick look menu that is located in your admin bar at the top left side of your dashboard screen.
Furthermore, From the contents in the drop-down menu, click on the view file option to open a new tab that contains a log of all the errors that have been generated by your site.
Using a Query Monitor.
Interestingly, another great plugin is the query monitor. It is one of the WordPress developer tools panel.
The query monitor allows your website to debug database queries, PHP errors, HTTP API calls, enqueued scripts and stylesheets and so on.
The query monitor has advanced features such as debugging of REST API calls, user capability checks and even Ajax calls.
As a result of this tool, the user can narrow down a large part of their output by theme or plugin. This helps them to identify plugins, themes, and other functions that are not performing well.
An alternative to this tool is the debug bar. This plugin adds a debug menu to the admin bar. It shows queries, caches and other useful debugging tips.
For what it’s worth I’ll recommend this to developers
Using New Relic.
Interestingly, This is another tool that will help you debug errors or other issues relating to your site. It is a premium tool so you should understand its worth.
Furthermore, this tool will help you monitor the user experience as well as find broken permalinks and map your WordPress architecture.
Because it is a premium tool, it can detect errors or issues on your site even before they happen. It analyses and improves your general site performance
Conclusion
In conclusion, WordPress Debug Mode is a valuable ally for developers seeking to create and maintain robust, error-free websites.
By enabling Debug Mode, you gain access to essential insights, error logs, and warnings that can significantly streamline the debugging process.