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:

1. WP_DEBUG

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.)

2. SCRIPT_DEBUG

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 );

3. SAVEQUERIES

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?

61 thoughts on “5 Ways to Debug WordPress

  1. Pingback: 5 Ways to Debug WordPress | WPLover

  2. 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.

  3. 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.

  4. @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.

  5. Pingback: Best On WordPress From The Past Week N.3 | wpCanyon

  6. Pingback: Notable Tech Posts – 2010.04.25 | The Life of Lew Ayotte

  7. Pingback: Ladíme WordPress a odstraňujeme chyby « WordPress.sk

    • 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.

  8. Pingback: mois-Blog - WordPress-Debug-Instrumente

  9. Pingback: Zajímavé články o WordPressu (v angličtině) « Fórum podpory WordPressu

  10. Pingback: Around the web | alexking.org

  11. Pingback: Workshop: Advanced WordPress with NYU’s Studio20, 5/8/11 | Daniel Bachhuber's weblog

  12. Pingback: Plugin Strategy | beAutomated

  13. Pingback: Yet Another WordPress Development Environment and Debugging Post | | Gabriel's BlogGabriel's Blog

  14. 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)

  15. Pingback: PHP, CGI/Perl Script Installation Service

  16. Pingback: #nyc12: Hacking WordPress in the Newsroom | danielbachhuber

  17. Pingback: The ‘all’ and ‘shutdown’ hooks | Mamaduka

  18. 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.

  19. Pingback: HOW TO DEBUG WORDPRESS | HOW TO DEBUG WORDPRESS

  20. Pingback: Jack Reichert » Debug WordPress

  21. Pingback: Jack Reichert » How to Debug WordPress

  22. Pingback: advancement to excellenceHow To Become A Top WordPress Developer | t1u

  23. Pingback: How To Become A Top WordPress Developer // advancement to excellence | DigitalMofo

  24. Pingback: How To Become A Top WordPress Developer // advancement to excellence « Graphic,web Design And Visual Media «

  25. Pingback: How To Become A Top WordPress Developer // advancement to excellence | Complete SEO Marketing News

  26. Pingback: How To Become A Top WordPress Developer // advancement to excellence | Buypappa blog

  27. Pingback: How To Become A Top WordPress Developer // advancement to excellence | MyOfflineTheme.com Skyrocket Your Offline Business Just Now

  28. Pingback: How To Become A Top WordPress Developer // advancement to excellence « Steve deGuzman

  29. Pingback: How To Become A Top WordPress Developer // advancement to excellence | Diancin Designs

  30. Pingback: How To Become A Top WordPress Developer // advancement to excellence | TuTsRUS - All Adobe Tutorials - Photoshop | Illustrator | Encore | Premeire | After Effects

  31. Pingback: How To Become A Top WordPress Developer // advancement to excellence | Web Design Kingston

  32. Pingback: How To Become A Top WordPress Developer // advancement to excellence | Máquina Semiótica

  33. Pingback: How To Become A Top WordPress Developer // advancement to excellence |Trax Asia™

  34. Pingback: How To Become A Top WordPress Developer // advancement to excellence | Roberto Baca

  35. Pingback: How To Become A Top WordPress Developer // advancement to excellence | Sandeep's Blog

  36. Pingback: How To Become A Top WordPress Developer // advancement to excellence - Peter Sousa Freelance Designer and Engineer

  37. Pingback: How To Become A Top WordPress Developer // advancement to excellence | Vietnam Visa Services online for airport travelers 2012

  38. Pingback: How To Become A Top WordPress Developer | Internet Design Solutions

  39. Pingback: 如何成为一个顶级的WordPress开发者? | 土人的国度

  40. Pingback: 5 דרכים לדבג בוורדפרס | ליקוטי שיבולים

  41. Pingback: 최고의 워드프레스 개발자가 되는 방법 | Webactually Korea

  42. Pingback: Plugins & Tools for WordPress Developers

  43. Pingback: Plugins & Tools for WordPress Developers | CMS Radar

  44. 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

  45. Pingback: Плагины и инструменты для WordPress разработчиков

  46. Pingback: Manage Easily Your Website Development With These Extremely Helpful WordPress Plugins and Tools

  47. 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

  48. 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

  49. 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!

  50. 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.