I'm working on a quick plugin for my work and what I need is for my plugin to load as early as possible as it uses ob_start to buffer everything that is going on. I can make the plugin load as the first one:

function my_plugin_load_first()
    $path = str_replace( WP_PLUGIN_DIR . '/', '', __FILE__ );
    if ( $plugins = get_option( 'active_plugins' ) ) {
        if ( $key = array_search( $path, $plugins ) ) {
            array_splice( $plugins, $key, 1 );
            array_unshift( $plugins, $path );
            update_option( 'active_plugins', $plugins );

Which works fine in normal circumstances. But the issue arises when cache is enabled as it loads very early on


Pretty much right after plugin.php, while the rest of the plugins are way down there. I can't seem to find how it had been done and if it can even be altared as it may perhaps be hardcoded into wordpress to detect cache plugins and automatically assign them to be loaded early on. Perhaps I can make my script to be seen as such.

  • Have you heard of Must Use Plugins? They get placed in a special directory, can't be switched on or off (they always are on), and get loaded before all other plugins. Is it this you are looking for?
    – leymannx
    May 10, 2019 at 21:36

1 Answer 1


By default WordPress first checks for any must-use plugins (plugins in the optional mu-plugins folder) and loads those. So the first plugins loaded will be those located in /wp-content/mu-plugins folder

Then, if you're running a multisite installation, it checks for plugins that are network-activated and loads those.

Then it checks for all other active plugins by looking at the active_plugins entry of the wp_options database table, and loops through those. The plugins will be listed alphabetically.

Here is info about the order WordPress loads everything: https://codex.wordpress.org/Action_Reference#Actions_Run_During_a_Typical_Request

You can learn more about WordPress plugin API here: https://codex.wordpress.org/Plugin_API/


Update: The real solution could be a Drop-in plugin, their priority is above mu-plugins and plugins.

So if you want to load that specific plugin first, then create /wp-content/mu-plugins/ folder and copy your plugin inside it, making sure it is first in alphabetical order

  • That is incorrect. advanced-cache.php loads before mu-plugins. Dec 14, 2021 at 16:15
  • 1
    @kirillrocks thank you, you are right. I've just corrected my answer beacause it was only partly correct.
    – twelvell
    Mar 28 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.