Debugging is a traditional technique used to debug fragments of software code to identify and resolve errors. Although websites running WordPress themes are usually working as intended, it may from time to time be necessary to turn on a debugger. Using debuggers, you can learn more about the way a particular WordPress plugin behaves, where there is a possible memory leak, as well as to identify the way scripts interact with each other, and whether any improvements can be made.
Debugging in WordPress
WordPress makes debugging quite easy. There are specific lines of code which you can add within your wp-config.php file that will enable debugging in native manner. Enabling WP_DEBUG alone will bring out all error messages on screen and hinder with your browsing experience. Therefore it’s usually best to not do this on a live site and log all of your DEBUG logs into a separate file. Open your wp-config.php file and find a space to put the following piece of code:
// Enable WP_DEBUG mode define('WP_DEBUG', true); // Enable Debug logging to the /wp-content/debug.log file define('WP_DEBUG_LOG', true); // Disable display of errors and warnings define('WP_DEBUG_DISPLAY', false); @ini_set('display_errors', 0); // Use dev versions of core JS and CSS files (only needed if you are modifying these core files) define('SCRIPT_DEBUG', true);
Save and close your edited wp-config.php file and all of your debugging errors will be logged into a file that you will find at /wp-content/debug.log. This technique usually is much more convenient than having to display all of the errors in your admin dashboard and / or your live website.
Tools for Debugging a WordPress Website
Another way to debug WordPress websites is to use browser extensions and / or WordPress plugins for that specific purpose. There are lots of browser tools you can use and probably hundreds of debugging plugins available. Let’s take a look at a few of the most popular debug tools you can use.
Firebug Browser Add-on
Firebug is a sophisticated debugging add-on that lets webmasters, developers and designers analyze their websites for possible errors, network problems, design flaws, and function interaction between languages. The less errors you experience on your websites, the faster the loading and response times, since each error still takes time to execute and present itself. Firebug is also known for its logging feature that lets you log all errors in one place for you to analyze and fix.
Knowing how long each query takes to complete can be a lifesaver when it comes to optimizing your website for maximum performance. Far too often webmasters install countless plugins that promise a set of features, but nobody ever talks about the cost of having those features – which usually ends up being server memory. So choose wisely which WordPress plugins to install for your website.
Although WordPress by default requires quite a bit of memory, it’s a known fact that some plugins like to eat more than they should! Debug Bar lets you dive deep into the ins and outs of your working MySQL and PHP systems to fully understand how scripts, queries and data interact with each other, and what can be done to optimize and improve your website performance.
This debugging WordPress plugin comes with some features other debug plugins are not offering and can be greatly useful when developing with WordPress. Query Monitor allows you for example to debug AJAX calls, REST API requests or redirects. You can further check your database queries, filter hooks, search for PHP errors and many more. Query Monitor also supports a couple of add-ons from other plugins, like add-ons from the Debug Bar plugin we mentioned earlier.
Log Deprecated Notices
Log Deprecated Notices can be of great use, especially if you are using deprecated files, functions or function arguments. This plugin will detect and log deprecated code and offer an alternative if available. When using this debugging WordPress plugin, you won’t need WP_DEBUG mode.
Conclusion: Debugging WordPress Websites
When it comes to internal debugging analysis, plugins like Debug Bar will usually always rise above the occasion, simply because such a plugin will be able to determine internal memory leaks and other potential errors, whereas Firebug will usually look at the outside of the website and how external scripts and plugins affect the performance and appearance of your website.
Default WP_DEBUG mode is enough to fully understand website errors and what should be done about them, external plugins make it more obvious and sometimes more easy to fix things. To learn more about troubleshooting and debugging your site, please also see the following articles: