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.

  1. First, you have to create a file. Open up your code editor and create a new .php file.
  2. 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 :
  3. <?php 
    /** 
     * Plugin Name: My first MU plugin 
     * Version: 1.0  
     */
    	
  4. Then add a line preventing direct access to the file. Not including this line would open up a security breach :
  5. <?php 
    /** 
     * Plugin Name: My first MU plugin
     * Version: 1.0 
     */  
    defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
    	
  6. You can add all the code you need after that.
  7. Save the file and name it my-first-mu-plugin.php for example.
  8. 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.
  9. 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.

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.