WordPress Performance Profiling with Query Monitor

When a WordPress page is slow, most developers reach for Google PageSpeed Insights or GTmetrix. These tools tell you what's slow from the outside — file sizes, render-blocking resources, connection times. But they can't tell you why WordPress took 800ms to generate the HTML that was then delivered.

Query Monitor fills that gap. It's a free WordPress plugin that instruments the page generation process itself — showing you every database query, every hook that fired, every PHP script that ran, every external HTTP request, every template file loaded, and exactly how long each took.

It's the most powerful free WordPress debugging and performance tool available. This guide teaches you how to use it effectively to diagnose and fix performance problems at the application level.

Installing Query Monitor

  1. Go to Plugins → Add New
  2. Search "Query Monitor"
  3. Install and activate

After activation, an admin toolbar item appears at the top of every page — both on the front end (when logged in) and in wp-admin. This is your Query Monitor dashboard trigger.

Access: Click any Query Monitor item in the admin toolbar to open the full panel.

Who sees it: By default, only Administrators see Query Monitor's output. This is important — your site visitors don't see it, even when you're debugging live.

The Query Monitor Interface

Query Monitor's panel attaches to the bottom of the page (like browser DevTools). It has several tabs, each addressing a different aspect of page performance. Below we cover the most important ones in detail.

01
Queries Tab (Most Important for Performance)

The Queries tab shows every database query executed during page generation.

What to Look For:

  • Total query count: Displayed at the top. Under 30–50 is typically fine for most pages. Over 100 warrants investigation. Over 200 is almost certainly a performance problem.
  • Total query time: Also shown at top. Under 100ms is good. Over 300ms for database alone is problematic.
  • Duplicate queries: Query Monitor highlights queries executed more than once. Duplicate queries indicate missing caching — the same data is being fetched from the database repeatedly when it should be cached after the first fetch.
  • Slow queries: Queries taking over a configurable threshold (default 0.05 seconds) are highlighted in red. These are your first optimisation targets.

Individual query details:

  • Query text (the actual SQL)
  • Execution time in milliseconds
  • Rows returned
  • Caller: Which function/method made this query — this is the key to fixing it

Example: Diagnosing an N+1 Query Problem

An N+1 query problem occurs when code fetches a list of objects (1 query) then fetches related data for each object individually (N additional queries). For a list of 50 posts that each need their author's name, this produces 51 queries instead of 1 or 2.

In Query Monitor, you'll see the same query pattern repeated many times with different IDs — a clear N+1 signature.

Fix: Use WP_Query with the fields argument, or use get_posts() with update_post_meta_cache and update_post_term_cache set to true to pre-populate caches.

Pro Tip: Use the filter/search box in the Queries panel to show only queries from a specific table, a specific plugin or theme, or only queries over a time threshold.
02
Hooks Tab (Understanding Execution Flow)

The Hooks tab shows every WordPress action and filter that fired during page generation, in execution order, with the number of callbacks attached to each.

What to Look For:

  • Slow hook callbacks: Query Monitor shows if a hook callback took significant time. If the_content filter is accumulating 200ms, some callback attached to it is the bottleneck.
  • Unexpected hooks: Hooks you don't recognise from plugins you don't use — potentially from abandoned or orphaned plugin code.
  • Hook timing issues: Understanding the execution order helps diagnose timing conflicts where one plugin hooks in too early or too late relative to another.
Pro Tip: Use the callback component filter to see only hooks from a specific plugin or theme — invaluable for plugin conflict diagnosis.
03
HTTP API Calls Tab

Shows every external HTTP request made during page generation — calls to external APIs, remote services, and CDNs initiated by WordPress or plugins.

What to Look For:

  • Slow external calls: An external API call taking 500ms stalls page generation for half a second. Every visitor waits.
  • Unexpected external calls: A plugin making calls to external servers you don't recognise could be a licensing check, telemetry or analytics collection, or unexpected data transmission.
  • Failed calls: HTTP errors (4xx, 5xx) from external services your plugins depend on.

Fixing Slow External HTTP Calls — Cache API responses:

If a plugin makes an external API call on every page load, its data should be cached using WordPress transients:

PHP
function get_external_data() {
    $cached = get_transient( 'my_external_data' );
    if ( $cached !== false ) {
        return $cached;
    }

    $response = wp_remote_get( 'https://api.external.com/data' );
    $data = json_decode( wp_remote_retrieve_body( $response ) );

    set_transient( 'my_external_data', $data, HOUR_IN_SECONDS );
    return $data;
}
Important: If a plugin is making uncached external calls on every page load, it's a bug — report it to the plugin developer.
04
Template Tab

Shows the template hierarchy — which template files WordPress evaluated and loaded to render the page.

What to Look For:

  • Incorrect template loading: If the wrong template is rendering a page, the Template tab shows exactly which file won and the full hierarchy that was evaluated.
  • Plugin template overrides: Some plugins override WordPress's template hierarchy. The Template tab reveals when this is happening.
  • Theme file identification: For complex themes with many template parts, this tab shows exactly which parts files were included and in what order.
05
Scripts and Styles Tab

Lists every JavaScript and CSS file enqueued for the page — handle, source URL, dependencies, and whether loaded in header or footer.

What to Look For:

  • Duplicate libraries: Two plugins loading different versions of jQuery, lodash, or other common libraries.
  • Header-loaded scripts: Scripts loaded in <head> without defer or async are render-blocking. The Scripts tab makes these visible.
  • Unnecessary enqueues: Plugins loading their scripts on pages where they're not needed. Combine with Asset CleanUp or Perfmatters to conditionally disable them.
  • Large file sizes: Large bundles contributing to page weight.
06
PHP Errors Tab

Shows all PHP errors, warnings, and notices generated during page generation — even ones suppressed by error reporting configuration.

What to Look For:

  • PHP Notices: Often harmless but can indicate deprecated code or logic issues.
  • PHP Warnings: More serious — undefined variable, division by zero. Usually indicates a bug.
  • PHP Deprecated: Code using deprecated WordPress or PHP functions that will break in future versions.
  • Fatal errors: If a fatal error is produced, Query Monitor captures it if possible.

The Component column shows which plugin or theme generated the error, making it easy to identify the responsible code.

Request and Environment Tabs

Request tab shows the parsed WordPress query — query type (single post, archive, search, etc.), queried object details, query variables, and the rewrite rule that matched. Useful for debugging permalink issues, custom query var problems, or unexpected page type detection.

Environment tab provides comprehensive technical information about the server:

  • PHP version and configuration: PHP version, memory limit, max execution time, PHP extensions installed, OPcache status (important for performance)
  • WordPress information: WordPress version, database version, memory usage, site URL, home URL
  • Active theme and plugins with file size information
  • Server information: Server software (Apache, Nginx, LiteSpeed), database server version

Advanced: Using Query Monitor Conditionally

For production debugging (investigating a problem on a live site without affecting visitors), Query Monitor can be shown only to specific users or via a secret cookie.

Show Only for Admins (Default)

By default, Query Monitor only displays for logged-in users with the view_query_monitor capability (Administrators have this automatically).

Authenticate via Cookie (Development)

For debugging when not logged in, set a cookie qm_auth with the value of a password hash. Add to wp-config.php:

PHP
define( 'QM_COOKIE_HASH', wp_hash( 'my-secret-phrase' ) );

Then set the cookie in your browser and Query Monitor appears even when logged out.

Query Monitor vs Xdebug vs New Relic

Tool Type Best For Setup
Query MonitorFree WordPress pluginWordPress-level profiling: queries, hooks, HTTP calls, templatesZero configuration
XdebugPHP extensionLine-level PHP profiling, step debugging, function tracingRequires server config
New Relic / Datadog APMEnterprise APMContinuous production monitoring, transaction tracing, alertingComplex setup, paid
Pro Tip: For the vast majority of WordPress performance work, Query Monitor is all you need. 99% of WordPress performance problems are diagnosable right here.

Performance Investigation Workflow

When a WordPress page is slow, this is the diagnostic process with Query Monitor:

Step 1: Measure baseline

Load the page and note Query Monitor's summary: total queries, total query time, total page generation time.

Step 2: Identify the dominant cost

Is most time in database queries? In hook callbacks? In HTTP API calls? The summary bar shows the breakdown.

Step 3: Drill into the biggest contributor

  • If database time dominates: Queries tab → sort by time → look for slow queries and duplicates
  • If hook time dominates: Hooks tab → look for slow callbacks
  • If external time dominates: HTTP API tab → look for slow or uncached calls

Step 4: Identify the responsible component

The "Caller" column in Queries, "Component" in Hooks — tells you which plugin, theme, or WordPress core is responsible.

Step 5: Fix and verify

Make the fix (add caching, optimise the query, fix N+1) and reload. Query Monitor shows the before/after immediately.

Quick Reference: What Each Tab Reveals

Tab Shows Key Signal
QueriesEvery database queryDuplicates, slow queries (>50ms), high total count
HooksActions and filters firedSlow callbacks, unexpected hooks
HTTP APIExternal HTTP requestsSlow/uncached API calls, failed requests
TemplateTemplate files loadedWrong template loading, plugin overrides
Scripts & StylesEnqueued JS/CSS filesDuplicate libraries, render-blocking scripts
PHP ErrorsErrors, warnings, noticesDeprecated code, undefined variables
RequestWordPress query varsPermalink issues, wrong query type detection
EnvironmentPHP, server, WP configOPcache off, low memory limit, old PHP

Frequently Asked Questions

Q: Should I leave Query Monitor active on a production site?
A: Yes — it's designed for this. It only shows output to users with the view_query_monitor capability (Administrators by default), and even when collecting data it adds minimal overhead (under 5ms typically). It can alert you to errors and performance regressions as they appear on your live site.
Q: Query Monitor shows 200 database queries on my homepage. Is this always bad?
A: High query counts are a warning sign but context matters. A heavily featured homepage with widgets, recent posts, and dynamic content might legitimately require 100+ queries even when well-optimised. Focus on query time (total and individual) more than raw count. Duplicate queries and queries over 50ms are more actionable signals.
Q: Can Query Monitor slow my site down for visitors?
A: No — it collects performance data in the background but only renders the panel when an Administrator loads the page. For non-admin visitors, Query Monitor adds negligible overhead (collecting timing data adds microseconds).

Final Thoughts

Query Monitor is one of the first plugins every WordPress developer should install. It turns performance diagnosis from guesswork into evidence-based investigation — you see exactly what's slow, where in the code it comes from, and can verify improvements immediately.

Install it now, even if your site feels fast. Understanding what's happening under the hood — how many queries your pages make, what hooks fire, which plugins make external calls — builds the intuition that separates developers who write performant WordPress code from those who don't.

Contact us for professional WordPress performance optimisation
Views: 142