What are WordPress MU-Plugins? (ok)
The Must-Use Plugins Directory
A mu-plugin is similar to a classic plugin, except that it is not stored in the plugins
directory of the wp-content
folder, but rather in the mu-plugins
directory, of the same folder. If you have never used mu-plugins before, this directory should not exist, but you can create it without any problem.
Note that the directory where you will store your mu-plugins is /wp-content/mu-plugins
, but you can change this by defining two constants in the wp-config.php
file: WPMU_PLUGIN_DIR
and WPMU_PLUGIN_URL
.
Be careful: if you define these two constants, WordPress won’t redefine them, so if the path is not valid, mu-plugins won’t be loaded. Moreover, in the wp-config.php
file, you must define these constants before the line where WordPress includes the wp-settings.php
file, that means you won’t be able to use some useful constants like WP_CONTENT_DIR
for example.
Our First Must-Use Plugin
C:\xampp\htdocs\wordpress4\wp-content\mu-plugins\hello-world.php
C:\xampp\htdocs\wordpress4\wp-content\themes\twentytwentyone\functions.php
Subdirectories
C:\xampp\htdocs\wordpress4\wp-content\mu-plugins\load.php
C:\xampp\htdocs\wordpress4\wp-content\mu-plugins\myplugin\myplugin.php
If you add a new folder containing another mu-plugin, you will have to edit the load.php
file. However, you can automate this process thanks to some PHP functions. Replace the content of the load.php
file by the following lines.
Last updated
Was this helpful?