How to make a WordPress mu-plugin

Creating a “mu-plugin” (must-use plugin) for WordPress effectively ensures critical functionalities are always active on your website. This plugin is automatically activated and cannot be disabled through the WordPress dashboard, making it ideal for essential features or customizations.

Another use case for a mu-plugin is to add extra functions to a plugin or the WP core. For instance, WP Staging has many filters and hooks that can provide more features to the WP Staging staging or backup feature. All of these documented filters can be added to a custom mu-plugin.

Introduction to Must-Use Plugins

Mu-plugins, or “must-use” plugins, are a special type of WordPress plugin. They are stored in a separate directory (wp-content/mu-plugins) and are automatically loaded by WordPress. These plugins are ideal for code that must always be executed, like custom functions for a website, and they are immune to accidental deactivation.

Advantages of Mu-Plugins

  1. Automatic Activation: Mu-plugins are automatically activated and cannot be accidentally deactivated.
  2. Enhanced Security: Since they can’t be deactivated from the admin panel, they offer a more secure way to implement critical functionalities.
  3. Ease of Management: Ideal for managing multiple WordPress sites, as it simplifies the maintenance of essential plugins.

Make a Mu-Plugin

1. Access Your Site’s Files

  • Access your website’s files through FTP or your web host’s file manager.

2. Locate the Mu-Plugin Directory

  • Navigate to the wp-content directory.
  • Check for the mu-plugins folder. If it doesn’t exist, create it.

3. Create Your Mu-Plugin File

  • Create a new PHP file for your mu-plugin. For example, my-mu-plugin.php.
  • Use a simple text editor to write your PHP code.

4. Add Code to Your Mu-Plugin

  • Your mu-plugin should start with a PHP opening tag <?php.
  • Below is the basic structure of a mu-plugin file:
PHP
<?php
/*
Plugin Name: My Custom Mu-Plugin
Description: A custom must-use plugin to enhance my WordPress site.
Version: 1.0
Author: Mickey Mouse
*/

// Your custom code goes here

Step 5: Upload Your Mu-Plugin

  • Upload the .php file to the mu-plugins directory on your server.

Step 6: Verify Activation

  • Since mu-plugins are automatically activated, check your site to ensure your custom code works.

Sample Mu-Plugin: Custom Admin Footer Text

For example, let’s create a simple mu-plugin that changes the footer text in the WordPress admin area.

PHP
<?php
/*
Plugin Name: Custom Admin Footer
Description: Changes the footer text in the WordPress admin area.
Version: 1.0
Author: Your Name
*/

add_filter('admin_footer_text', function () {
    echo 'Customized by Tony Stark - Powered by WordPress';
});

Conclusion

Creating a mu-plugin is a straightforward process that can greatly enhance the functionality and security of your WordPress site. By following the above steps, you can implement always active customizations, providing a consistent and reliable experience for your site.

Remember to test your mu-plugins thoroughly on a staging environment before deploying them to a live site to ensure they work as expected.

Author: Rene Hermenau

I'm René Hermenau, founder of WP STAGING. I've been building WordPress infrastructure software since 2013 and writing code on GitHub since 2011. My repos live at github.com/rene-hermenau. WP STAGING started as a small developer project solving the same problem I kept hitting on client work: there was no fast, safe way to clone a WordPress site for staging or migration without breaking serialized data, file paths, or media references. Today we are a team of more than 10 people. The free plugin runs on hundreds of thousands of WordPress installations, and the Pro version powers backup, migration, and staging workflows for agencies, hosting platforms, and ecommerce stores. I'm still hands-on with the codebase and technical architecture. Our releases are built as a team, but many of the core architectural decisions are ones I helped design, test, and evolve over the years: how we handle large database exports, how we keep memory usage flat on multi-GB sites, and how we make migrations atomic against partially written tables. "When you touch code, leave it 10% better than before and write a test." If you're stuck on a WP STAGING question, the docs are at wp-staging.com/docs. If you hit a bug, file it on GitHub at github.com/wp-staging. Our team reads everything that lands there.