Short answer: WordPress mu-plugins are must-use plugins: PHP files in wp-content/mu-plugins that WordPress loads automatically on every request, before normal plugins, and that cannot be deactivated from the dashboard. Create the folder, add a single PHP file with a plugin header, lint it with php -l, and use a loader file for code in sub-folders.
Key takeaways
- Mu-plugins always run, load before normal plugins and cannot be switched off in wp-admin.
- WordPress only scans PHP files directly in wp-content/mu-plugins, not sub-folders.
- They are ideal for security rules, custom endpoints, environment guards and site-critical features.
- No automatic updates and no activation hooks, so you own maintenance and setup logic.
- A fatal error in a mu-plugin breaks the whole site; lint before every deploy.

Most WordPress developers meet mu-plugins by accident: a host adds a file to wp-content/mu-plugins, or a plugin you cannot find in the plugin list keeps doing something. Once you understand them, mu-plugins become one of the most useful tools for code that must always run, whatever a client clicks in the dashboard.
I run the front end and booking system of a production site as mu-plugins: the custom page rendering, a REST booking endpoint with spam protection, and site-wide SEO filters. This guide explains how mu-plugins work, when to use them, and how to deploy them without taking a site down.
What are mu-plugins in WordPress?
Mu-plugins, short for must-use plugins, are PHP files in the wp-content/mu-plugins folder that WordPress loads automatically on every request. They load before normal plugins, in alphabetical order by file name, and they cannot be activated, deactivated or deleted from the WordPress dashboard. They appear in a separate Must-Use tab on the Plugins screen.
Must-use plugin: a plugin file that WordPress always loads from the mu-plugins directory, without activation.
WPMU_PLUGIN_DIR: the constant that holds the path to the mu-plugins directory, by default wp-content/mu-plugins.
The “mu” originally came from WordPress MU, the multisite edition, but must-use plugins work on every WordPress install, single site or network.
Mu-plugins vs normal plugins: what is the difference?
The key differences are control and timing. Normal plugins are switched on and off by administrators and can update automatically. Mu-plugins always run, load earlier, and are managed only through files on the server, which makes them reliable but also your responsibility to maintain.
| Aspect | Mu-plugins | Normal plugins |
|---|---|---|
| Activation | Automatic, always on | Activated in wp-admin |
| Deactivation from dashboard | Not possible | Possible |
| Load order | Before normal plugins, alphabetical | After mu-plugins |
| Sub-folders | Not scanned | Each plugin in its own folder |
| Updates | Manual, by you | From WordPress.org or vendor |
| Activation hooks | Do not run | Run on activation |
| Best for | Site-critical, always-on code | Optional features |
mu-plugins vs functions.php vs drop-ins
Developers often put site code in the theme’s functions.php. That works until the theme changes and the code disappears. Mu-plugins keep site logic independent of the theme. Drop-ins are a different mechanism: specially named files such as object-cache.php that replace parts of WordPress core behaviour.
| Place | Loaded when | Survives theme change | Use for |
|---|---|---|---|
| Theme functions.php | Only with that theme active | No | Display and theme features |
| Normal plugin | When activated | Yes | Optional features |
| Mu-plugin | Always | Yes | Site-critical logic |
| Drop-in | When the named file exists | Yes | Caching, database, maintenance overrides |
Drop-ins such as advanced-cache.php are used by page cache plugins; my guide to page caching with Cache Enabler and nginx shows one in practice.
When should you use a mu-plugin?
Use a mu-plugin for code that the site depends on and that nobody should be able to turn off by accident: security hardening, custom REST endpoints used by the front end, custom post types that store business data, environment-specific behaviour and small site-wide tweaks. Keep optional, user-facing features as normal plugins.
- Security: disabling XML-RPC, hiding versions, blocking user enumeration.
- Business logic: custom post types and REST routes that the theme or app needs.
- Environment guards: no indexing and no outgoing email on staging.
- Performance tweaks: limiting revisions, disabling unused features.
- Hosting integration: cache purge hooks, object cache helpers.
Avoid putting theme-specific display code in mu-plugins; if you switch themes, that code should go with the theme. Avoid large third-party plugins as mu-plugins, because you lose their update path.
Step 1: create your first mu-plugin
Create the mu-plugins folder inside wp-content, owned by the web server user, and add a single PHP file. A plugin header is optional for loading but makes the file readable in the Must-Use list. Lint the file before WordPress loads it.
# Create the folder and a file (adjust the path and owner to your site)
cd /var/www/example.com/htdocs
sudo -u www-data mkdir -p wp-content/mu-plugins
sudo -u www-data nano wp-content/mu-plugins/site-essentials.php
# Check syntax before WordPress loads it
php -l wp-content/mu-plugins/site-essentials.php
# Confirm WordPress sees it
wp plugin list --status=must-use
<?php
/**
* Plugin Name: Site Essentials
* Description: Small site-wide tweaks that must always be active.
* Version: 1.0.0
* Author: Your Name
*/
defined( 'ABSPATH' ) || exit;
// Hide the WordPress version from the generator meta tag
remove_action( 'wp_head', 'wp_generator' );
// Limit post revisions stored per post
add_filter( 'wp_revisions_to_keep', fn() => 20 );
Reload wp-admin and open Plugins, Must-Use. Your plugin should appear with its name and description. If you use WP-CLI, wp plugin list --status=must-use shows the same list; my WP-CLI guide covers more commands.
Step 2: load mu-plugins from sub-folders
WordPress only loads PHP files that sit directly in the mu-plugins folder. If you upload a plugin folder there, nothing happens. Keep larger mu-plugins in their own folders and load them from one small loader file at the top level.
<?php
/**
* Plugin Name: MU loader
* Description: Loads must-use plugins that live in sub-folders.
*/
defined( 'ABSPATH' ) || exit;
$mu_plugins = array(
'my-security/my-security.php',
'my-booking/my-booking.php',
);
foreach ( $mu_plugins as $file ) {
$path = WPMU_PLUGIN_DIR . '/' . $file;
if ( is_readable( $path ) ) {
require_once $path;
}
}
The loader runs in alphabetical order with other top-level files, so give it a name such as 00-loader.php if it must run first. Check is_readable() so a missing file does not cause a fatal error.
From my own work: My production setup keeps each mu-plugin as one self-contained file: the page renderer, the blog renderer and the booking API. Single files keep the deploy script simple, because it can lint each file with php -l on the server and install it with the right owner in one command.
Real-world mu-plugin examples
These short examples show typical must-use code. Each is a complete file you can drop into wp-content/mu-plugins after linting.
A custom REST endpoint
Front ends and integrations that call your own endpoints should not break because someone deactivated a plugin. Registering routes in a mu-plugin keeps them always available.
<?php
/**
* Plugin Name: Site API
* Description: Custom REST endpoints that the front end depends on.
*/
defined( 'ABSPATH' ) || exit;
add_action( 'rest_api_init', function () {
register_rest_route( 'site/v1', '/health', array(
'methods' => 'GET',
'permission_callback' => '__return_true',
'callback' => fn() => array( 'ok' => true, 'time' => time() ),
) );
} );
An environment guard for staging
Staging copies of production sites often send real emails to customers or get indexed by Google. This mu-plugin uses wp_get_environment_type(), set with WP_ENVIRONMENT_TYPE in wp-config.php, to block both outside production.
<?php
/**
* Plugin Name: Environment guard
* Description: Safer defaults on staging: no search indexing, no outgoing email.
*/
defined( 'ABSPATH' ) || exit;
if ( 'production' !== wp_get_environment_type() ) {
add_filter( 'pre_option_blog_public', '__return_zero' ); // discourage indexing
add_filter( 'pre_wp_mail', '__return_false' ); // block real emails
}
Security hardening
Disabling XML-RPC, removing the X-Pingback header and blocking pingback methods is a common must-use plugin, because security settings should never be switchable from the dashboard. Combine it with server-level rules for the strongest effect.
How does load order work?
WordPress loads wp-config.php, then mu-plugins in alphabetical order, then network-activated plugins on multisite, then active plugins, and finally the theme’s functions.php. Code in a mu-plugin therefore runs before plugin code, which is useful for filters that must be in place early.
- wp-config.php and constants.
- Drop-ins such as object-cache.php and advanced-cache.php, when present.
- Must-use plugins, alphabetically.
- Network-activated plugins (multisite).
- Active plugins.
- The theme, child theme first.
The muplugins_loaded action fires after all mu-plugins have loaded, and plugins_loaded after normal plugins. If your mu-plugin needs a function from a normal plugin, wait for plugins_loaded before calling it.
Can you change the mu-plugins folder?
Yes, with the WPMU_PLUGIN_DIR and WPMU_PLUGIN_URL constants in wp-config.php, defined before WordPress loads its settings. This is rarely needed, but useful for custom directory layouts such as Bedrock-style projects.
// wp-config.php: move the mu-plugins folder (rarely needed)
define( 'WPMU_PLUGIN_DIR', dirname( __FILE__ ) . '/wp-content/must-use' );
define( 'WPMU_PLUGIN_URL', 'https://example.com/wp-content/must-use' );
Step 3: deploy mu-plugins safely
Because a mu-plugin always loads, a syntax error breaks the whole site immediately, including wp-admin. Upload new versions to a temporary path, lint them on the server with the same PHP version, and only then move them into place in one atomic step.
# Deploy one mu-plugin safely: upload to /tmp, lint, then install atomically
scp site-api.php user@server:/tmp/site-api.php
ssh user@server 'sudo php -l /tmp/site-api.php &&
sudo install -o www-data -g www-data -m 644 /tmp/site-api.php
/var/www/example.com/htdocs/wp-content/mu-plugins/site-api.php &&
rm /tmp/site-api.php'
For automated pipelines, the same steps fit into CI; see deploying WordPress with GitHub Actions. Keep mu-plugins in version control and write a rollback note: deleting or renaming the file restores the previous behaviour.
Why is my mu-plugin not working?
When a mu-plugin seems to do nothing, check the location first, then syntax, permissions, hooks and caching. Most problems come from a file inside a sub-folder or a hook that fired before the code was added.
| Symptom | Likely cause | Fix |
|---|---|---|
| Not in the Must-Use list | File is inside a sub-folder | Move it to the top level or use a loader |
| White screen or 500 error | PHP fatal error | Check the PHP error log; run php -l; rename the file |
| Listed but no effect | Hook already fired or wrong priority | Use an earlier hook or adjust priority |
| Works for admins only | Page cache serving old HTML | Purge the page cache and CDN |
| Permission denied in logs | Wrong file owner or mode | chown to the web user, chmod 644 |
| Old code still running | OPcache | Reload PHP-FPM or wait for revalidation |
If the site is down and you cannot reach wp-admin, rename the file over SSH or SFTP, for example to site-api.php.off. WordPress ignores files that do not end in .php. Turning on debug logging with WP_DEBUG_LOG helps you read the exact error.
Security considerations for mu-plugins
Because mu-plugins always run and are invisible to most dashboard users, attackers sometimes hide backdoors there after compromising a site. Include the mu-plugins folder in malware scans and file integrity checks, and review its contents whenever you take over a site. Unknown files with obfuscated code, base64 strings or eval calls are red flags.
- List the folder during every audit:
ls -la wp-content/mu-plugins/. - Keep file permissions at 644 and owned by the site user, never world-writable.
- Track mu-plugins in Git so unexpected changes show up in a diff.
- Remove hosting mu-plugins you do not need after migrating away from a host.
Scheduled tasks are another place where must-use code helps: if you replace WP-Cron with a system cron, a mu-plugin can define DISABLE_WP_CRON checks and log cron health in one always-on place.
Mu-plugins on WordPress multisite
On a multisite network, every mu-plugin runs on every site. That makes them perfect for network-wide policies, but you must check get_current_blog_id() or site options if code should only run on some sites. Network administrators cannot disable them per site from the dashboard.
WordPress mu-plugins checklist
- Folder wp-content/mu-plugins exists with correct ownership.
- Each mu-plugin is a single top-level PHP file, or loaded by a loader.
- Every file has a plugin header and an ABSPATH check.
- Files are linted with php -l before deploy.
- Code waits for plugins_loaded when it needs other plugins.
- Mu-plugins are in version control with a rollback note.
- Staging uses an environment guard.
- Page cache and OPcache are cleared after changes.
Want this done on your own server or site?
I am Saizul Amin, a web developer and technical SEO consultant. I set up and harden VPS servers, migrate WordPress sites, fix indexing problems and build automations. See my portfolio or get in touch.
FAQ
What are mu-plugins in WordPress?
Mu-plugins, or must-use plugins, are PHP files placed in wp-content/mu-plugins that WordPress loads automatically on every request, before normal plugins. They cannot be activated or deactivated from the dashboard, which makes them ideal for code that must always run, such as security rules, custom endpoints or site-wide settings.
Where is the mu-plugins folder?
By default it is wp-content/mu-plugins. WordPress does not create it, so you create it yourself. The location can be changed with the WPMU_PLUGIN_DIR and WPMU_PLUGIN_URL constants in wp-config.php, although that is rarely necessary.
Why is my mu-plugin not working?
The most common reasons are that the file sits inside a sub-folder, which WordPress does not scan, a PHP syntax error, wrong file permissions, or the code runs on a hook that has already fired. Check Plugins > Must-Use in wp-admin and the PHP error log.
What is the difference between mu-plugins and normal plugins?
Mu-plugins load automatically, earlier than normal plugins, in alphabetical order, and cannot be deactivated in the dashboard. They do not get automatic updates and activation hooks do not run. Normal plugins can be switched on and off and updated from WordPress.org or vendors.
Are mu-plugins the same as WordPress multisite plugins?
No. The name comes from WordPress MU, the old multisite version, but must-use plugins work on any WordPress site. On a multisite network they apply to every site in the network.
Can a broken mu-plugin take my site down?
Yes. Because a mu-plugin always loads, a fatal PHP error in it breaks the whole site, including wp-admin, and you cannot deactivate it from the dashboard. Always lint files with php -l before deploying and keep server access to rename the file if needed.
Sources
- WordPress Developer Resources: Must Use Plugins
- WordPress Developer Resources: Plugin header requirements
- WordPress Developer Resources: wp_get_environment_type()
- WordPress Developer Resources: register_rest_route()
- WP-CLI: wp plugin list
- PHP Manual: Command line options (php -l)

Saizul Amin is a web developer, AI automation engineer and technical SEO consultant from Dhaka, Bangladesh (B.Sc. in CSE, BUBT). Since 2017 he has worked in digital marketing, WordPress, IT infrastructure and server administration, including the bilingual SHR Bangladesh website for DGHS, WordPress sites for UK and US clients, and the ShobFree tools platform. He runs this blog on his own Ubuntu VPS with nginx, Redis and CloudPanel, and tests the guides here on it. Portfolio: saizul.com

