When dealing with a WordPress website laden with numerous plugins, performance issues may arise. Identifying the root cause can prove challenging. Typically, developers resolve these WordPress errors by either trimming problematic code sections or systematically deactivating plugins to pinpoint the culprit.

This method could potentially require a substantial investment of time. However, an expedited alternative is available: the Query Monitor plugin. It offers a streamlined method for pinpointing performance concerns and gaining a deeper understanding of your WordPress site’s operations.

Brief Overview of Query Monitor

Query Monitor is a complimentary plugin designed specifically to assist in troubleshooting performance and development issues on your WordPress website. It furnishes insights into database queries, scripts, timing, and other pertinent details without any copied content.

Once Query Monitor is installed, you’ll notice a valuable addition to the top menu bar. Clicking on it reveals a dropdown menu indicating the number of queries being executed on the current page.

This information encompasses details such as loading times, query types employed, various components involved, and other pertinent factors. This dataset aids developers in gaining insights into website errors and devising effective solutions for them.

John Blackbourn developed the project, which is available on both the official WordPress Plugin Repository and GitHub.

The Query Monitor tool undergoes regular updates, with the development team promptly addressing any reported bugs and providing support.

Set up Query Monitor

  • Access your WordPress dashboard.
  • Navigate to the “Plugins” section located in the left-hand menu.
  • Select ‘Add New Plugins.
  • In the search bar located at the top right corner, type ‘Query Monitor.”
  • After locating the Query Monitor plugin in the search results, opt for “Install Now.
  • After installation, click “Activate” to enable the plugin.
  • It now appears on the list in the plugins section without requiring any additional setup.

Selecting options from the dropdown menu allows you to access in-depth information on database queries, CSS styles, active hooks, and HTTP API calls.

System requirement of Query Monitor

To utilize Query Monitor, confirm that your setup includes WordPress (compatible with versions up to three years old) and PHP version 7.4 or newer. For further details, please refer to the Query Monitor website.

What makes Query Monitor valuable for developers?

The Query Monitor plugin serves as a detective tool for developers, aiding them in identifying areas for improvement by pinpointing plugins or elements that could be contributing to resource issues or conflicts.

It efficiently addresses performance hurdles, empowering developers to enhance the code or substitute problematic components. This proves advantageous for website owners and developers aiming to optimize the speed and smoothness of their websites.

Let’s consider a fundamental developer task to illustrate the usefulness of Query Monitor.

Typically, determining the page load time and the number of active queries on a page necessitates utilizing code. WordPress offers two functions, namely get_num_queries() and timer_stop(), which can aid in identifying performance bottlenecks. Utilizing these code snippets can be instrumental in recognizing areas for improvement, although comprehending them thoroughly may demand a certain level of technical expertise.

Query Monitor simplifies tasks by automatically integrating functions into your code and verifying outcomes, eliminating the need for manual intervention. It provides visibility into the quantity of database queries and delivers valuable analysis regarding your website’s performance and functionality.

Features of Query Monitor include

1) Database Queries

  • Monitor notifications for queries exhibiting tardiness, redundancy, or anomalies.
  • The outcomes can be sorted according to the query type, the relevant component (like a plugin, theme, or WordPress core), or the invoking function.
  • Provide a comprehensive overview of each query type, including detailed breakdowns within aggregate views.

2) PHP Error Reporting

  • Display PHP errors alongside details about the component triggering the problem, the call stack, and a noticeable warning in the admin toolbar.
  • In the code, identify any usage of deprecated or incorrect functionality.

3) Template Information

Identify the template filename, explore the complete template hierarchy, and ascertain the loaded or unloaded template parts, particularly focusing on block and classic themes.

4) Blocks and Full Site Editing (FSE)

Examine the characteristics of blocks and their functionalities within post content and Full Site Editing (FSE).

5) Rewrite Rules and Query Parameters

Display the matched rewrite rules, linked query strings, and query variables in a transparent layout.

6) Enqueued Scripts and Stylesheets

Retrieve information on the loaded scripts and stylesheets, including their dependencies. Receive notifications for any broken dependencies.

7) Language Settings

Retrieve details regarding your language configuration and the loaded translation files (MO and JSON files) for each text domain.

8) HTTP API Requests

Monitor HTTP API requests, recording the response code, the corresponding component, and the duration. Implement alerts for any unsuccessful or erroneous requests.

9) User Capability Checks

Receive reports detailing user capability checks, showcasing both the outcomes and the parameters utilized for each check.

10) Environment information

Comprehensively gather information about PHP, the database, WordPress, and the web server in one place.

11) Conditional functions

To understand the current context or state, you can observe the outcomes of various WordPress conditional functions, such as is_single(), is_home(), and others.

12) Transient Data and Multisite Operations

Identify updated transient data and understand how to use switch_to_blog() and restore_current_blog() in Multisite installations.

How to utilize WordPress Query Monitor?

After successfully installing and activating Query Monitor from the WordPress Dashboard, proceed with the subsequent steps.

  • Access your WordPress dashboard.
  • Proceed to the Plugins section.
  • Go to Installed Plugins and locate Query Monitor… then click on it.
  • Now, please select the Settings option.
  • Please click the “Set authentication cookie” button.

Let’s now thoroughly examine each segment of the Query Monitor plugin.

Overview

The primary tab provides a concise overview of your website, showcasing key metrics such as page generation time, peak memory usage, database query duration, and the quantity of database queries executed.

Database Queries

When a user requests or submits information, it prompts a database query.

The Query Monitor function tracks queries and displays them in logs. This feature enables users to observe both successful and unsuccessful query executions. Moreover, users can filter queries based on their type and associated components.

Object cache

The Overview panel within Query Monitor provides comprehensive insights into different facets of your website, encompassing the object cache as well. In the absence of a persistent object caching plugin, Query Monitor will display a notification indicating this.

A persistent object cache plugin enhances performance by storing outcomes of tasks like database queries, enabling rapid retrieval.

If you encounter the notification “External object cache not utilized,” it’s advisable to install a persistent caching plugin such as Redis or Memcached. Doing so can notably boost your website’s performance.

Timings

The Timings panel within Query Monitor tracks and presents data on the duration and approximate memory usage associated with the qm/start and qm/stop actions pertaining to the designated function name.

It’s important to recognize that the times and memory usage displayed in the Timings panel are estimations and should be treated as such.

Logs

The Log tab within Query Monitor is an advanced functionality that allows you to document messages and variables. This capability is immensely valuable for diagnosing technical issues or overseeing your website for potential problems.

Upon initial installation of Query Monitor, the tab will appear empty as no logging variables have been configured yet.

Request

The Request feature showcases the user’s query variable along with the custom query, revealing any additional query strings associated with the request.

Admin Screen

The admin screen section displays the activities taking place within the WordPress admin panel. It offers a roster of components accessible from the admin panel and identifies errors stemming from the absence of PHP files.

Scripts

In the Scripts tab of Query Monitor, you can view all the queued scripts and styles linked to the current request. It also identifies any malfunctioning or unresponsive scripts attributed to external dependencies.

Styles

The Styles tab within Query Monitor functions similarly to the Scripts tab, focusing on enqueued CSS rather than highlighting JavaScript. It serves as a valuable tool for debugging and optimizing site performance.

Optimizing your website involves minimizing the number of stylesheets loaded, akin to streamlining scripts. This process enhances loading times by reducing file sizes and HTTP requests.

Hooks and Action

In every WordPress site, hooks and actions are essential for implementing custom functionality using WordPress’s built-in controls. While customization is vital, it can sometimes result in issues. Troubleshooting errors in such cases can be quite challenging.

Query Monitor provides a helpful built-in tool for identifying errors related to hooks and actions. This tool allows users to filter actions and hooks by core, theme, or plugin. Furthermore, it offers complete names and references, simplifying their location within the code for efficient debugging.

Languages

The Language tab identifies malfunctioning or inaccessible files on a multilingual website and showcases the language configurations.

HTTP API calls

This tab presents a comprehensive view of server-side queries, showcasing response codes, timeout logs, and failed requests. Its utility lies in enabling real-time observation of responses, thereby streamlining the debugging process for server-side code.

Transient Updates

WordPress has the capability to store API responses in its database. This feature becomes especially useful when dealing with APIs that impose limits on the number of requests allowed within a certain timeframe. Within Query Monitor, the Transient Updates section displays these transients along with details such as their size and associated components.

Capability Checks

This functionality is not enabled by default but can be activated by adding the code to the wp-config.php file. Capability Checks perform capability assessments for each user on the page, displaying the parameters and outcomes.

Environment

This offers an extensive analysis of the WordPress ecosystem, covering the PHP, Database, and WordPress aspects. Each segment provides valuable insights into the environment, detailing information such as the MySQL version, PHP memory allocation, WordPress version, and other pertinent details.

Conditional

The Conditionals feature within Query Monitor showcases all relevant WordPress conditionals for the current request, indicating whether each conditional evaluates to “True” or “False.” This provides a comprehensive insight into the conditional logic applied during the page load process.

Other tools to debug and enhance WordPress performance include.

1) Google PageSpeed Insights
PageSpeed Insights (PSI) by Google is a popular tool used for analyzing the speed of a website on both mobile and desktop platforms.

2) GTmetrix
GTmetrix is a web-based utility designed to evaluate the speed of websites. It assesses various metrics such as load time, page size, and number of requests, ultimately delivering a score and suggesting improvements for optimization.

Conclusion

The WordPress Query Monitor plugin stands out as an invaluable resource for debugging, providing comprehensive insights presented in a user-friendly manner. Its ability to swiftly identify the performance implications of plugins, themes, or functions makes it an essential tool for website optimization.

The Query Monitor plugin stands out for its smooth incorporation of a menu into the admin toolbar. This menu provides a quick summary of the current page, and upon activation, it displays detailed information in a panel.