When managing a WordPress site with numerous plugins, performance issues can arise, making them challenging to identify. Developers often resolve these issues by excluding problematic code or disabling plugins one by one. This method can be time-consuming. However, there’s a more efficient solution: the Query Monitor plugin. This guide will cover everything you need to know about Query Monitor, including its purpose, functionality, and how to use it effectively to debug and improve your WordPress site’s performance.

Table of Contents

  1. Brief Overview of Query Monitor Plugin
  2. Why Is Query Monitor Useful for Developers?
  3. Features of WordPress Query Monitor
  4. System Requirements of Query Monitor
  5. How to Use WordPress Query Monitor

Brief Overview of Query Monitor Plugin

Query Monitor is a free plugin designed to help you troubleshoot performance and development issues on your WordPress site. It provides insights into database queries, scripts, timing, and more. Once installed, Query Monitor adds a convenient entry to the top menu bar, offering a dropdown list that reveals the number of queries running on the current page, loading time, query types, components, and other details. This data empowers developers to better understand and address website errors.

John Blackbourn developed Query Monitor, and it is available on both the official WordPress Plugin Repository and GitHub. The plugin is regularly updated, and the development team provides prompt support and fixes for all reported bugs.

What Does Query Monitor Do?

Query Monitor helps you:

  • Identify PHP errors
  • Monitor memory usage
  • Analyze database queries, including those from specific plugins
  • Track HTTP API calls on your WordPress site
  • Explore enqueued scripts and styles, along with their dependencies
  • Understand hooks and actions influencing your site’s behavior
  • Examine theme template files in use
  • Check languages and translations within your site
  • Review rewrite rules affecting your site’s URLs
  • Analyze blocks present in the WordPress block editor
  • Access general environment information about your site
  • Gain insights into the performance of WordPress admin screens

System Requirements of Query Monitor

To use Query Monitor, your system should have WordPress (versions up to three years old are supported) and PHP version 7.4 or higher. For more details, you can visit the Query Monitor website.

Why Is Query Monitor Useful for Developers?

The Query Monitor plugin helps developers identify areas for improvement by revealing plugins or assets causing resource issues or conflicts. It efficiently addresses bottlenecks, allowing for code enhancements or replacing problematic elements. This benefits website owners and developers aiming to optimize performance.

To understand the benefit of using Query Monitor, consider a simple task that typically requires leveraging code—finding out the page load time and the number of active queries on the page. WordPress offers two simple functions: get_num_queries() and timer_stop(). These functions help identify performance bottlenecks, requiring a certain level of technical knowledge to interpret effectively. Query Monitor automates the process, saving you from doing it manually.

Features of WordPress Query Monitor

Here is a comprehensive overview of Query Monitor’s features:

  1. Database Queries
  • Notifications for slow, duplicate, or erroneous queries.
  • Filtering options by query type, responsible component (plugin, theme, WordPress core), and calling function.
  • Aggregate views for each query type, providing a detailed breakdown.
  1. Template Information
  • Display of template filename, complete template hierarchy, and loaded or unloaded template parts (for block and classic themes).
  1. PHP Errors
  • Presentation of PHP errors with details on the responsible component, call stack, and a visible warning in the admin toolbar.
  • Identify deprecated or “Doing it Wrong” functionality usage in the code.
  1. Blocks and Full Site Editing (FSE)
  • Insight into blocks and associated properties within post content and FSE.
  1. Rewrite Rules and Query Strings
  • Display of matched rewrite rules, associated query strings, and query vars.
  1. Enqueued Scripts and Stylesheets
  • Information on enqueued scripts and stylesheets, including dependencies and alerts for broken dependencies.
  1. Language Settings
  • Details on language settings and loaded translation files (MO files and JSON files) for each text-domain.
  1. HTTP API Requests
  • Record of HTTP API requests with response code, responsible component, and time taken, along with alerts for failed or erroneous requests.
  1. User Capability Checks
  • Reporting of user capability checks, including the result and parameters passed to the capability check.
  1. Environment Information
    • Detailed information about PHP, the database, WordPress, and the web server.
  2. Conditional Functions
    • Values of all WordPress conditional functions, such as is_single(), is_home(), etc.
  3. Transients and Multisite Functionality
    • Identification of updated transients and usage of switch_to_blog() and restore_current_blog() on Multisite installations.
  4. Redirects
    • Automatic addition of an HTTP header containing the call stack whenever a redirect occurs.
  5. AJAX Calls
    • Monitoring of Ajax calls for sending and fetching data in real time without loading the complete web page.
  6. REST API
    • Debugging information in the header of an authenticated WordPress REST API request.
  7. Authentication
    • By default, only the admin of a single-site installation and the super admin of a WordPress Multisite can view the logs. You can configure an authentication cookie to see the logs even when logged in as a user.
  8. Privacy Statement
    • Query Monitor operates with a commitment to user privacy, not collecting or transmitting any data to third parties.

How to Use WordPress Query Monitor

After installing and activating Query Monitor from the WordPress Dashboard, follow these steps:

  1. Go to Plugins.
  2. Click Installed Plugins → Query Monitor.
  3. Click Settings.
  4. Click on the “Set authentication cookie” button.

Overview

The first tab provides an overview of your website, including page generation time, peak memory usage, database query time, and database queries.

Database Queries

Query Monitor tracks and logs database queries, displaying successful and unsuccessful executions. You can filter by query type and component.

Object Cache

The Overview panel includes information about your site’s object cache. If you lack a persistent object caching plugin, install one like Redis or Memcached to enhance performance.

Timings

The Timings panel records and displays the time taken and approximate memory usage during specific actions.

Logs

The Log tab allows you to log messages and variables for troubleshooting. Initially, it will be empty until you configure logging variables.

Request

The Request feature shows the query variable for the current user and highlights the custom query strings.

Admin Screen

This section shows activities on the WordPress admin panel, listing accessed components and any errors due to unavailable PHP files.

Scripts

The Scripts tab lists all queued scripts and styles, highlighting any broken or unresponsive scripts due to external dependencies.

Styles

Similar to the Scripts tab, the Styles tab focuses on enqueued CSS, helping to debug site performance by reducing the number of stylesheets.

Hooks and Actions

Query Monitor identifies errors caused by hooks and actions, allowing you to filter by core, theme, or plugin and providing references for debugging.

Languages

The Language tab identifies broken or unavailable files and displays language settings for multilingual websites.

HTTP API Calls

This tab shows server-side queries, response codes, timeout logs, and failed requests, aiding in debugging server-side code.

Transient Updates

Displays transients, their sizes, and components, useful for APIs with limited request allowances.

Capability Checks

By default, this is inactive but can be activated via the wp-config.php file. It performs capability checks for each user on the page, displaying parameters and results.

Environment

Provides a complete overview of the WordPress environment, including PHP, Database, and WordPress sections with relevant information.

Conditionals

Displays all WordPress conditionals relevant to the current request, indicating whether each evaluates to “True” or “False.”

Summary

The WordPress Query Monitor plugin is a powerful debugging tool, offering detailed information in an easily understandable format. It’s especially beneficial for quickly identifying the impact of plugins, themes, or functions on a website’s performance. The seamless integration into the admin toolbar provides quick snapshots of the current page and comprehensive data upon menu item selection.

Which of these components do you often use to keep your site healthy? Try this plugin out and share your experience in the comments below.

Frequently Asked Questions

Q1. Where is Query Monitor located in WordPress?
A. Query Monitor is accessible through the WordPress admin bar. Clicking on the summary opens the full Query Monitor interface, displayed as a window overlay on the current front or backend page.

Q2. How do I optimize a WordPress query?
A. Optimizing your WordPress database involves table optimization through SQL commands, cleaning up unwanted data, deleting post revisions, removing spam comments, deleting unused tags, eliminating pingbacks and trackbacks, and uninstalling unused plugins and themes.

Q3. Where are WordPress error logs located?
A. To access error logs in WordPress, go to your /wp-content/ folder using the File Manager. Look for the debug.log file within this folder, which contains a comprehensive record of all logged WordPress errors, warnings, and notices.


Similar Posts