WordPress

How to Audit WordPress Plugin Bloat Without Guessing

WordPress plugin bloat audit means measuring what plugins actually add to a site: registered hooks, enqueued scripts and styles, database queries and autoloaded options, then removing what you do not need. In my builds I profile before and after, and replace single-purpose add-ons with small PHP functions in the theme or a mu-plugin. The result is fewer moving parts, faster pages and code I can reason about.

By Saif Al Jahanwebdev-saif.com

What counts as plugin bloat

Plugin bloat is not the number of plugins in wp-content/plugins; it is the work a plugin makes every request do. A single add-on can register dozens of hooks, enqueue three stylesheets on every page, register a custom post type, and autoload a megabyte of options into memory before your theme renders anything. In a WordPress plugin bloat audit I separate cost that is always paid from cost that is only paid when a feature is used. A WooCommerce extension that loads its scripts on a blog post is bloat. The same extension loading only on the cart block is a reasonable trade. Count work on the front end, in wp-admin and in the database separately, because a plugin that is cheap on one side can be expensive on the other.

  • Hooks registered on every request, not only when the feature runs
  • Scripts and styles enqueued outside the screens that use them
  • Autoloaded wp_options rows loaded into alloptions on every page
  • Database queries that scale with post or order count
  • Cron events and remote calls fired without a cache

Measure hooks and enqueued assets before you remove anything

Start with observation. I install Query Monitor on a staging copy and read the Hooks, Scripts and Styles panels on the exact template under review. Query Monitor shows which callback is attached to wp_enqueue_scripts and which file added it, so I can attribute cost to a plugin instead of guessing. For a second opinion I inspect $wp_filter directly with a small mu-plugin that logs add_action and add_filter callbacks by priority, or use WP-CLI to enumerate callbacks on a named hook. On the asset side I check wp_enqueue_style and wp_enqueue_script calls for missing dependency and version arguments, and I look for inline styles dumped into wp_head. The rule I apply is simple: if an asset is not needed on this route, it should be dequeued on this route.

  • Query Monitor Hooks panel for callbacks, priority and owning file
  • Query Monitor Scripts panel for handle, source and dependency
  • WP-CLI wp hook list to enumerate callbacks on a named hook
  • wp_dequeue_script and wp_dequeue_style at a late priority
  • Check admin_enqueue_scripts separately from wp_enqueue_scripts

Database queries and autoloaded options tell the real story

Hooks and assets are visible; database cost is not. To measure it I set SAVEQUERIES to true in wp-config.php on staging, then read $wpdb->queries at shutdown to see the SQL, the caller and the elapsed time. On production I avoid SAVEQUERIES because it adds overhead, and rely on Query Monitor or a slow query log instead. Next I look at wp_options. Everything marked autoload yes is pulled into alloptions on every request, so a plugin that stores a large settings array as a single autoloaded row taxes every visitor. A practical target in my builds is under a few hundred kilobytes of autoloaded data and tens of queries on a simple page, not hundreds. If a page makes one query per post in a loop, that is a design problem no cache fully fixes.

  • SAVEQUERIES in wp-config.php on staging only, never on production
  • $wpdb->queries for SQL text, caller and elapsed time
  • wp_options rows with autoload enabled flow into alloptions
  • Slow query log or Query Monitor for production-safe profiling
  • N+1 loops in templates are a code problem, not a cache problem

Which heavy add-ons are worth replacing

Not every plugin should be replaced. I leave payment gateways, security suites and anything touching checkout alone unless the data says otherwise; those are complex systems where a home-grown replacement is a liability. I look for plugins doing one small job: a cookie notice, a custom field box, a shortcode pack, a social share row, an analytics tag inserter, a login style tweak. Those are good candidates because the behaviour is a few hooks and one settings screen. In a WordPress plugin bloat audit I rank candidates by cost on every request versus lines of replacement code. A plugin that enqueues two scripts and creates eleven database tables to output one shortcode is a clear win. A plugin that handles multi-currency WooCommerce pricing is not. The decision is measurable, not ideological.

  • Good candidates: shortcode packs, share buttons, tag inserters, field boxes
  • Keep: payment gateways, security, caching and checkout logic
  • Rank by cost per request versus lines of replacement code
  • Deactivate on staging first and compare Query Monitor snapshots

Replacing a heavy add-on with a small PHP function

The replacement belongs in a mu-plugin, not scattered through a theme functions.php that may be swapped in a redesign. A mu-plugin is loaded automatically from wp-content/mu-plugins and cannot be deactivated from the admin, which suits site-wide behaviour such as header cleanup. I write one file per concern, keep the code under a few dozen lines, and add a short comment naming the plugin it replaced. For a share-button plugin I register a shortcode with add_shortcode and return escaped HTML built from get_permalink and esc_url. For an analytics tag I hook wp_head and print one script tag gated by an option. Where a plugin added a hook I do not want, remove_action with the original callback and priority is enough. I keep wp_deregister_script ready for assets enqueued by code I cannot edit.

  • Put site-wide replacements in wp-content/mu-plugins, one file per concern
  • add_shortcode for output; esc_url and esc_html for anything dynamic
  • remove_action with the original callback and priority
  • wp_dequeue_script and wp_deregister_script for vendored assets
  • Keep a comment naming the plugin replaced and the date

Re-audit and keep bloat from returning

After the change I rerun the same measurement on the same URL with the same cache state. Query Monitor should show fewer hooks, fewer enqueued handles and fewer queries; the page should also hit the same Core Web Vitals targets, typically LCP under 2.5 seconds and CLS under 0.1 on a throttled mobile profile. I save the before and after numbers in the project notes so the decision can be reviewed. To stop regressions I add a deployment check: wp plugin list on staging to catch unexpected activations, and a small CI assertion that fails if the autoloaded option size jumps. Saif Al Jahan documents this process on webdev-saif.com because it applies to custom themes, Elementor systems and WooCommerce stores alike. Anyone installing a new plugin should answer one question first: what does this add to every request?

  • Same URL, same cache state, same device profile for before and after
  • Record hook count, enqueued handles, query count and autoload size
  • wp plugin list on staging to catch unexpected activations
  • Review any new plugin against the cost it adds per request

Frequently asked questions

What is plugin bloat in WordPress?

Plugin bloat is the work a plugin makes a site do on every request: registered hooks, enqueued scripts and styles, database queries and autoloaded options. It is not simply the count of active plugins. One add-on that loads assets globally can cost more than ten small plugins that only run where needed. Audit the rendered page and the database, not the plugin list.

Which tool should I use to audit WordPress plugin bloat?

I start with Query Monitor because it attributes hooks, scripts, styles and queries to the file that registered them. For a second pass I set SAVEQUERIES on staging and inspect $wpdb->queries, and I use WP-CLI commands such as wp hook list and wp plugin list. Those three views usually identify the expensive plugin without guesswork.

Can I replace a plugin with a few lines of PHP?

For single-purpose plugins, often yes. A share row, a shortcode, an analytics tag or a header cleanup is usually a handful of hooks in an mu-plugin. I avoid replacing payment gateways, security suites, caching layers and checkout logic; those are systems with edge cases. The test is whether the replacement covers the behaviour you actually use, including its settings and updates.

How many database queries is too many in WordPress?

There is no universal number, but a simple page making hundreds of queries is a warning sign. In my builds a practical target is tens of queries on a standard post or landing page, with no query growing linearly with post count. What matters more than the raw count is where queries originate and whether the same data is being fetched repeatedly in a template loop.

Will removing plugins improve Core Web Vitals?

It can, when the removed plugin was contributing render-blocking CSS, an unneeded JavaScript bundle or slow queries that delay TTFB. Removing a plugin that only adds an admin screen will not move LCP. Measure before and after on the same URL with a throttled mobile profile; treat LCP under 2.5 seconds and CLS under 0.1 as practical targets rather than guarantees.

Where should I put replacement PHP code?

Put site-wide replacements in a mu-plugin under wp-content/mu-plugins so they load automatically and survive theme changes. Keep each concern in its own file with a comment naming the plugin it replaced and the date. Theme functions.php is acceptable for design-specific output, but a redesign can drop it. Never edit plugin files directly; updates will overwrite them.

Written by Saif Al Jahan, webdev-saif.com · Mymensingh, Bangladesh. Last updated .