Debugging WordPress with Query Monitor

Query Monitor is a free WordPress plugin that turns the admin toolbar into a debugging panel. It shows every database query executed on the page, which hooks ran, HTTP API calls, PHP errors, template parts loaded, and much more — all without touching a single config file.

Problem: A WordPress page loads slowly or renders incorrectly, but there is no easy way to see which database queries ran, which hooks fired, which templates were loaded, or where PHP errors occurred — without editing source files.

Solution: Install the Query Monitor plugin — it adds a toolbar panel showing slow queries, all hooks with their callbacks, template file paths, HTTP API calls, and PHP errors without requiring any code changes or var_dump() calls.

Install it via WP-CLI or from the Plugins screen:

wp plugin install query-monitor --activate

Once active, the admin toolbar shows a summary row. Clicking it opens a full panel with tabs:

Queries tab — every SQL query with its execution time, the function that called it, and the component (plugin/theme) responsible. Slow queries are highlighted in red.

Hooks tab — all actions and filters that fired on the current request, with the callbacks attached to each.

Template tab — the current template file, all template parts included, the matched rewrite rule, and the query vars.

Log custom data to the Query Monitor panel from your code:

// Log a message
do_action( 'qm/debug', 'Processing order %d', $order_id );

// Log a warning
do_action( 'qm/warning', 'Cache miss for post %d', $post_id );

// Log an error
do_action( 'qm/error', 'API call failed: %s', $error_message );

// Log structured data
do_action( 'qm/info', $my_complex_array );

Query Monitor also identifies which plugin or theme registered a slow query. This makes it easy to spot a poorly written plugin that runs 50+ queries on every page load:

// Enable SAVEQUERIES in wp-config.php to store all queries in $wpdb->queries
define( 'SAVEQUERIES', true );

// Inspect the query log programmatically
global $wpdb;
$slow_queries = array_filter( $wpdb->queries, function( $q ) {
    return $q[1] > 0.05; // queries taking more than 50ms
} );
var_dump( count( $slow_queries ) );

NOTE: Query Monitor is safe to use on a production server because it only shows the debug panel to logged-in administrators. However, enabling SAVEQUERIES in wp-config.php stores every query in memory for the duration of the request — avoid this on high-traffic production sites.