WordPress must use plugins are plugins that are always loaded and cannot be deactivated within the WordPress admin.
A bit of a hidden feature, must use plugins require a little setup initially:
- First, you will need to create an
mu-pluginsdirectory within the WordPress content directory. The
mu-pluginsdirectory will sit alongside your normal
pluginsdirectory, normally at
wp-content/mu-pluginsunless you’ve moved or renamed the WordPress content directory.
- Then, any files you upload into that directory will be loaded automatically. Just be aware that dropping a folder into
mu-pluginswon’t do anything, only standalone files will load.
- Must use plugins are always on and cannot be disabled within the admin area.
- Must use plugins load before normal plugins.
- Must use plugins will never check for or show available updates.
- Must use plugins do not trigger plugin activation hooks.
Tips & Tricks
- Dropping a file into the
mu-pluginsdirectory means that code runs automatically, without having to log into the admin. This comes in handy when you need to do things like force a WordPress admin user.
- If you want to load a normal plugin as a must use plugin, just drop the plugin folder into the
mu-pluginsdirectory and then create a
plugin-loader.phpfile (any name will do) that does a
requirefor the main plugin file.
- Files in the
mu-pluginsdirectory load alphabetically. If you need to manually control the load order, you can simply rename the files.
- You can move or rename the
mu-pluginsdirectory by setting these constants in your
define( 'WPMU_PLUGIN_DIR', __DIR__ . '/wp-content/required-plugins' ); define( 'WPMU_PLUGIN_URL', 'http://mydomain.com/wp-content/required-plugins' );