mu-plugin
mu-plugin (Must-Use Plugin): a special WordPress plugin loaded automatically on every request that can't be disabled from the dashboard — ideal for infrastructure code.

A mu-plugin (short for Must-Use Plugin) is a special kind of WordPress plugin, stored in the wp-content/mu-plugins/ directory, that is loaded automatically on every request, doesn't appear in the dashboard's Plugins screen and therefore can't be disabled by an administrator. That makes it the tool of choice for infrastructure code that must always be active: environment detection, cache configuration, PaaS integration, low-level security rules.
Technical definition
How WordPress loads mu-plugins
At the start of every request, WordPress scans the mu-plugins/ directory and automatically includes every PHP file at the root of that directory — without recursion. A file placed at mu-plugins/myplugin.php is loaded. A file placed at mu-plugins/myplugin/index.php is ignored, unless a loader file at the root includes it explicitly. This constraint keeps the system simple: there's no activation to manage and no database lookup to find out which plugins are active — every file at the root is active, period.
Loading happens very early in the lifecycle of a WordPress request, before regular plugins and before the theme. Hooks such as muplugins_loaded let you run code at the moment all mu-plugins have loaded but regular plugins haven't yet.
Differences from regular plugins
- Location:
mu-plugins/instead ofplugins/. - Activation: automatic and permanent. No link to the
wp_optionstable. - Interface: not visible in the admin. Only an informational entry appears in the plugin list to show that a mu-plugin is loaded, with no action buttons.
- Install hooks: none. A mu-plugin can't declare a
register_activation_hook()function, since it has no activation cycle. - Automatic updates: none. The file has to be updated manually (or through a Git deployment).
Current challenges
Their role in infrastructure-as-code architectures
In a WordPress project deployed on a PaaS (Upsun, Fly.io, Platform.sh) with Bedrock, mu-plugins become the integration point between the WordPress application code and the runtime environment. That's where you put:
- Detection of the PaaS environment variables (
PLATFORM_RELATIONSHIPS,PLATFORM_ROUTES) to configure Redis, the database and public URLs dynamically. - HTTPS handling behind a proxy (reading the
X-Forwarded-Protoheaders). - Perimeter security rules that must run before WordPress has fully loaded.
- Specialized endpoints that must not load WordPress (health checks, monitoring).
All of this code has to be versioned in Git, reviewed in a pull request and guaranteed active in production — which is exactly what mu-plugins promise.
The mu-plugin as a Trojan horse
The "can't be disabled" advantage has a flip side: if a mu-plugin has a bug or introduces a vulnerability, there's no emergency switch in the dashboard to turn it off. The only fix during an incident is to delete the file over FTP, SSH or through a new deployment. For that reason, mu-plugin code should be audited more rigorously than a regular plugin's, and tested in staging before any production deployment.
Practical applications
In my experiment on securing WordPress with Infrastructure as Code, mu-plugins carry all the logic that has to stay in PHP but must never be switched off: an upsun-security.php mu-plugin that implements a nano-WAF (HTTP method filtering, User-Agent allowlist/blocklist, dynamic CSP), and a health-check.php mu-plugin that answers on /health without loading WordPress. This split keeps zero application plugins in the dashboard while preserving the essential logic in PHP.
Frequently Asked Questions
What sets a mu-plugin apart from a regular plugin?
Three fundamental differences: (1) a mu-plugin lives in wp-content/mu-plugins/ (or web/app/mu-plugins/ in a Bedrock structure) instead of wp-content/plugins/, (2) it is loaded automatically on every request with no manual activation, and (3) it doesn't appear in the Plugins screen of the WordPress dashboard — so it can't be disabled from the admin. A PHP file dropped into mu-plugins/ becomes active across the whole site on the next page load.
Why use a mu-plugin rather than a regular plugin or code in functions.php?
A mu-plugin is the right choice for infrastructure code that must never be switched off, not even by mistake: Redis cache configuration, HTTPS detection behind a proxy, low-level security filtering, integration with a PaaS. Unlike functions.php, a mu-plugin is independent of the theme (it survives a theme change). Unlike a regular plugin, it can't be disabled by an administrator who ticks the wrong box. And unlike the core, it's versioned in the project's Git repository — so it can be reviewed in a pull request.
What are the limitations of mu-plugins?
mu-plugins have three limitations compared with regular plugins: (1) no recursive loading — only PHP files at the root of mu-plugins/ are loaded automatically, subdirectories are ignored, (2) no activation/deactivation hooks — since a mu-plugin is never activated or deactivated, (3) no updates from the dashboard — maintenance happens exclusively at the file level, which is good for reproducibility but can be a problem if you depend on an ecosystem that updates frequently.