How to use WordPress’ Debugging Mode

Posted OnNov 26, 2013     CategoryDevelopment     CommentsNo comment

In this article, we will talk about the uses of the WordPress debug mode, how to enable it and how to use the different debug flags available.

What is Debugging?

Debugging in WordPress allows you to force all the PHP errors to be displayed and in turn makes it easier to troubleshoot issues with your WordPress core files, themes and plugins.

This feature is normally used by plugin/theme developers, however it can be helpful for normal WordPress users when attempting to track down issues with plugins, themes or core WordPress files.

In addition to the primary debug mode in WordPress, there are additional modes that you may also find helpful. Below we will outline the basics of each on.

  • WP_DEBUG_LOG
    • This flag will enable the log feature of debugging mode. When this is enabled, all errors will be saved to a file (/wp-content/debug.log) so that you can review them later.
  • WP_DEBUG_DISPLAY
    • This flag is on by default and should only be used if you don’t want the errors to be rendered on your website. This is a great option (when used with WP_DEBUG_LOG) if you are working on a live site and you don’t want people to see errors on your site.
  • SCRIPT_DEBUG
    • This option will force WordPress to use the development version of the core CSS/JS files instead of the normal ones loaded.
  • SAVEQUERIES
    • This option will save all queries used to an array and it will allow you to display these queries simply by using $wpdb->queries. Please be aware that this option will add overhead to your site and should be disabled when not actively being used.

Setup

In this section, we will show you how to setup WP_DEBUG as well as the other flags mentioned above.

For this, you will need access to edit the wp-config.php file located on your website file system. Please contact your hosting provider for information on how to do this.

Open wp-config.php using a text editor (some hosting providers have one built into their control panel).

Located towards the bottom of the document, you should find a line that has “define(‘WP_DEBUG’, false);” (without the double quotes). Change false to true, then save the file (and upload it if using FTP).

Visit your website, if any PHP errors are in play, you should now see them on the pages that are having issues. If you don’t notice any difference, it is possible that the issue with your site (the reason we are using debug mode) is not PHP related.

To disable debugging mode, simply reverse the changes made above (set true back to false). It is as simple as that!

If you wish to enable any of the other debugging flags, you can do so by ADDING the correct line (listed below) under the “define(‘WP_DEBUG’, false);” line in the wp-config.php file.

define(‘WP_DEBUG_LOG’, true);
define(‘WP_DEBUG_DISPLAY’, false);
define(‘SCRIPT_DEBUG’, true);
define(‘SAVEQUERIES’, true);

Again, to disable the changes, simply remove these lines (NOT the WP_DEBUG line) or change their values.

That’s it!

Leave a Reply

Your email address will not be published. Required fields are marked *

Send this to friend