Errors in your WordPress template code can cause all kinds of problems. In this week’s WordPress Wednesday, we’re going to cover a couple of options for tracking down and fixing those errors.
WordPress has a built-in
WP_DEBUG option that can be set in your
wp-config.php file. The option is set to false by default; to turn it on, update the below line to read:[php]
define(‘WP_DEBUG’, true);[/php] This results in the template errors being printed at the top of your website — great for development environments, but not so handy otherwise. Douglas Neiner posted a great explanation of WordPress’s built-in debugging, as well as his own recommended configuration for displaying the errors in very specific situations, like only when the site is in the development environment; when a user is logged in; or simply outputting the messages to an error log rather than displaying them.
If you like your debugging tools a little snazzier, there are also a number of plugins that can do the job. My personal favourite is the Debug Bar plugin.
The plugin adds a button to the WordPress admin bar; when clicked, it displays debugging messages. You can also add a PHP/MySQL console by installing an additional plugin. This tool was originally only available on WordPress.com hosted sites; the WP team recently created a plugin so those hosting their own WordPress sites could use the tool as well.
To get the full range of functionality for the Debug Bar, you still need to make some edits to your
To display PHP Warnings and Notices,
WP_DEBUG needs to be enabled, but there’s no need to display it; simply update your
WP_DEBUG option to turn debugging on, and add the
WP_DEBUG_DISPLAY as shown below to ensure the errors aren’t outputted on your site:[php]
[/php]To display and track MySQL queries,
SAVEQUERIES will also need be enabled in the
wp-config.php file, like so:[php]define(‘SAVEQUERIES’, true);[/php]Do you have any tips or tools for debugging your WordPress sites? Share them in the comments!