Troubleshooting WordPress using the debug mode

      Comments Off on Troubleshooting WordPress using the debug mode

Are you getting strange WordPress results? Pages that don’t work like you intended? And your browser is not showing you any related errors? It looks like it’s time to do some troubleshooting, using the built in debug mode of WordPress!

What options do I have?

WordPress comes with a few number of built in options that allow you debug any issues you might have with your website. These are:

    This is the general toggle for the WordPress debug mode and can be found in your \wp-config.php file.
    This variable allows to you to log all errors to a file named debug.log located in your \wp-content\ folder.
    With this variable you can toggle whether the errors should be shown on screen.

When do I use each option?

The type of debugging you want to do should depend on your situation. Is your production website causing troubles? Or is it the development version your messing with? Based on the situation you can choose to show all errors generated on screen. Or you can choose to show no errors at all, but silently log them to a file. That last one is what you probably want to use in production. After all, you don’t want to annoy your users with nasty errors. If the site is in production, and you’re the only one actually using it, you can just enable the debug mode to show you everything that’s wrong. If the errors you’re encountering are AJAX related, you’ll want to enable logging as well. That way you don’t miss out on anything.

So.. how do I use these options?

First open up your wp-config.php and locate the line that says define('WP_DEBUG', false);. If we want to enable the debug mode, all we have to do is change this to: define('WP_DEBUG', true);. This will force WordPress to start showing all notices and errors that were previously hidden. Do you also feel the need to log all errors? Add this to the next line of wp-config.php: define('WP_DEBUG_LOG', true);. Not only will you get to see all errors, they will also be written to file: \wp-content\debug.log. The last option is useful if you want to suppress the errors on your website, but log them anyways. You can add the following rule to your wp-config.php file: define('WP_DEBUG_DISPLAY', false);. This last variable defaults to true. So disabling has to be done by defining it, in contrast with the other two variables.

That’s all there is to know about debugging WordPress, using the built-in functions. Happy bughunting!