How to create a MU plugin
A « MU plugin », or « Must Use plugin », is a special kind of plugin that can't be deactivated. To « deactivate » it, you just have to delete the plugin file.
- First, you have to create a file. Open up your code editor and create a new .php file.
- The first thing to do is to add an opening php tag and add a standard plugin header. You don't need to get fancy here. A plugin name and a version number are enough :
- Then add a line preventing direct access to the file. Not including this line would open up a security breach :
- You can add all the code you need after that.
- Save the file and name it
- You now have to put the file on your site. Unfortunately, you can't do this via the WordPress admin, like you can with a regular plugin. Access your site via FTP or SFTP with your favourite FTP client.
- Once you're logged in to your site, copy the file in the
/wp-content/mu-plugins/folder. This folder will not exist if that's your first MU plugin, so you'll simply have to create it first.
<?php /** * Plugin Name: My first MU plugin * Version: 1.0 */
<?php /** * Plugin Name: My first MU plugin * Version: 1.0 */ defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
Voila ! You just created a MU plugin and activated it on your site ! You can now check it works properly, and close your FTP client.