📢 Introducing Fathom Extension for MainWP: Track All Child Site Stats from One Dashboard.

Why Use the wp profile WP-CLI Command?

wp profile - WP CLI Command

What is the wp profile Command in WP-CLI?

wp profile command is designed for finding where and what is slowing a site down. As with any performance benchmarking, multiple runs will need to be used. Start by running the common commands for wp profile multiple times. This will help you find what is causing WordPress to load slowly on a site.

wp profile stage

This command will output a number of options in the table. They are broken down as:

  • bootstrap is where WordPress is setting itself up, loading plugins and the main theme, and firing the init hook.
  • main_query is how WordPress transforms the request (e.g. /2016/10/21/moms-birthday/) into the primary WP_Query.
  • template is where WordPress determines which theme template to render based on the main query, and renders it.

This command will load WordPress, as if a user requested it in a browser.

wp profile stage bootstrap

This command will show the results for only when WordPress is loading.

wp profile hook --all --spotlight

The spotlight option will show you where those hooks are being used.

wp profile hook --all --spotlight --url=https://mainwp.com/presales-faq/

In this example command a specific page on the MainWP site is simulated loading in a user’s browser, then it will display which plugins and theme files are being loaded on it. You can use this command to load a specific URL page and then compare between those pages.

wp profile hook --all --spotlight --skip-plugins=contact-form-7

In this example command, wp profile hook will profile the hooks being used by WordPress, then will simulate skipping a specific plugin, which might be causing performance issues on a site.

You can compare the results (with/without specific plugins active), but without having to use WP-CLI to deactivate a plugin.

wp plugin deactivate contact-form-7

This would be the command that would need to be run to deactivate a plugin to be able to run the spotlight on a specific URL, but using the --skip-plugin option, you do not have to actually deactivate a plugin for it to be not included in the results.

wp profile hook --all --spotlight --url=https://mainwp.com/presales-faq/
wp profile hook plugins_loaded --url=https://mainwp.com --fields=callback,time,location

This command will load the plugins which are needed on the site URL being profiled, then it will show which fields are causing the performance issue. With minor digging, you will be able to find which exact plugins are causing issues on the site with regards to performance. So by finding the plugins causing load issues on the site page, you will disable those plugins from loading on specific pages or changing those plugins with plugins which are more performance optimized.

All of the wp profile commands mentioned in the post are in this Gist.

Using wp profile command is similar to using New Relic, but without having to set up a New Relic APM account, installing a New Relic WordPress plugin, or having to login to New Relic and drill through the results to find what plugin or database query might be causing performance issues. By using WP-CLI more and more, it will become second nature and will improve your site maintenance.

Looking for something?

Privacy laws apply to businesses that collect personal information. Since no personal information is collected by the MainWP plugins, no privacy laws apply to the MainWP plugins. This includes GDPR, UK DPA 2018, PIPEDA, Australia Privacy Act 1988, LGPD, PIPL, and other privacy laws.
Donata Stroink-Skillrud
Donata Stroink-Skillrud
President of Agency Attorneys

Your Download Is Just One Click Away

…or just download the plugin.

By entering your email, you agree to our Terms of Service and Privacy Policy.