A “Must-Use” plugins are special in WordPress – they cannot be disabled and run before any other plugin.
Being ran earlier is important when you need to ensure your code runs before another plugin.
To create a “Must-Use” plugin you will need access to the files and folders on your server – this may be through your web host’s “cPanel” account or FTP.
- Browse to the wp-content directory
- Create a new directory called mu-plugins – so you have /wp-content/mu-plugins
- Browse to the mu-plugins directory
- Create a new text file and give it an appropriate name followed by .php – for example itsg_mu_plugin.php
- This leaves you with /wp-content/mu-plugins/itsg_mu_plugin.php
- Edit the file and add the following to the top of the file (you can change the details to suit)
<?php /* Plugin Name: wpdevguides.com must use plugins Description: code that is used always Version: 1.0.0 Author: WP Developer Guides Author URI: wpdevguides.com */
- Save the changes – you now have a “Must Use” plugin!
- Code that you add to this plugin will be ran early in the WordPress loop – critically – before any other plugin is ran.
- The main plugin file must be directly in the mu-plugins directory. Additional files can be in other folders.