5 Ways to Debug WordPress

Many plugin and theme authors don’t take full advantage of some really helpful debugging tools in WordPress. Here’s a quick run-down of five cool tools for debugging:


define( 'WP_DEBUG', true );

It’s no secret I love this constant and everything it stands for. Define it in wp-config.php and you’ll start seeing PHP notices and also WordPress-generated debug messages, particularly deprecated function usage.

(Added June 27, 2010: You may wish to check out my Log Deprecated Notices plugin.)

There’s also WP_DEBUG_DISPLAY and WP_DEBUG_LOG, which enable you to log these to a wp-content/debug.log file. I’ve added some inline documentation that describes these both well. Some use WP_DEBUG on a live site and just make sure it gets logged.

WP_DEBUG will often reveal potential problems in your code, such as unchecked indexes (empty() and isset() are your friend) and undefined variables. (You may even find problems in WordPress itself, in which case you should file a bug report.)


In the admin, WordPress minimizes and concatenates JavaScript and CSS. But WP also comes with the “development” scripts, in the form of dev.js and dev.css. To use these instead:

define( 'SCRIPT_DEBUG', true );


The WordPress database class can be told to store query history:

define( 'SAVEQUERIES', true );

When this is defined, $wpdb->queries stores an array of queries that were executed, along with the time it takes to execute them.

The database class has additional error and debugging tools, which are documented on the Codex (though when in doubt, check the source).

4. The ‘all’ and ‘shutdown’ hooks

There’s an ‘all’ hook that fires for all actions and filters. Example usage:

add_action( 'all', create_function( '', 'var_dump( current_filter() );' ) );

You’ll be surprised how many hooks get executed on every page load. Good for troubleshooting and identifying the right hook.

There’s also a ‘shutdown’ hook you can use in combination with, say, SAVEQUERIES, and write the query information to the database. It’s the last hook to run.

5. Core Control

There are plenty of great developer-oriented plugins out there, but I’m not sure any list would be complete without Dion Hulse’s Core Control plugin. It is comprised of five modules covering Filesystem methods, HTTP methods, HTTP logging, Cron tasks, and upgrades. A must-have.

This list is by no means exhaustive, just some quick hits to get you started. What tools do you use?

Published by

Andrew Nacin

Lead developer of WordPress, living in Washington, D.C. Follow me on Twitter.

61 thoughts on “5 Ways to Debug WordPress”

  1. WP Developer Assistant is one of my favorites; it’s a snazzy little plugin with a few features that help make debugging easier, my favorite of which has to be the actions/filters list showing everything that’s currently hooked.

    Thanks for the post Andrew, I knew about WP_DEBUG but I had no idea we had SCRIPT_DEBUG and SAVEQUERIES at our disposal. Great heads up.

  2. It’s sad, but I know only the first method to debug WordPress. Others are very new to me, and useful, too.

    There’s a plugin of Yoast.com, that can help us to debug, too. It displays useful information for developer.

    Thanks for sharing.

  3. @Austin: I forgot about that one, thanks! Looks like it could use an update for some of the other major WP globals, but obviously it gets the job done.

    @Mark: WP Developer Assistant looks pretty cool, I’ll have to check it out.

    @DBT: At least you knew WP_DEBUG. 🙂 Many plugin developers don’t.

    1. Despite it being an information overload, I do use it from time to time. I usually write it to avoid printing filters with ‘gettext’ in the name, though.

  4. There is another way to deal with wordpress debugging. WordPress FirePHP Debugger plugin shares an elegant, simple, and more maintainable way of debugging wordpress via the web browser.

    Main features:
    Automatic detection of FirePHP server library inside php include path or separated directory
    Early loading of the debugger (before WordPress engine starts)
    No modifications to WordPress core or configuration files
    Automatic enabling of WordPress debug mode
    Handles all php fatal errors (no more blank pages and logs parsing)
    Logs WordPress deprecated functions and arguments
    Safe debugging on live site
    SQL queries log
    PHP superglobals and constants
    System information (WordPress and server environment)

  5. Great tips there. I didn’t know the “all” hook. I will definitely use this one.
    + Activating WordPress debug but hiding it all and redirecting to the log is also very good. Thanks Andrew.

  6. Hi Nacin,

    Great stuff that you make.

    I just wanted pointed out that if your problem is about scripts you can try like you said:

    define(‘DEBUG_SCRIPTS’, true);

    and also this could fix the problem and give you the clue

    define(‘CONCATENATE_SCRIPTS’, false);

    Congrats great work

  7. I actually have a tendency to agree with everything that ended up being authored inside “5
    Ways to Debug WordPress | Andrew Nacin”. Thanks
    a lot for all the advice.Thanks for the post,Blanca

  8. I personally blog too and I am posting a little something alike to this excellent post, “5 Ways to Debug WordPress | Andrew Nacin”.
    Would you mind in case I personallyemploy a little of your own points?
    Many thanks -Connor

  9. First, looks like you have some spam comments here, I’d get rid of them. Second, this was great for me to read, even though I new about most of these items. It spiked my curiousity though as I didn’t know there was a “create_function()” function… looking deeper into that function now!

  10. Great post, I use this in conjunction with debugWP – which is more geared towards optimisation but non the less useful when debugging aspects like memory leaks due to excessive queries

Comments are closed.