Snippet: How to disable a network enabled plugin for one or more sites?

WordPress Multi-site feature was introduced in 3.0 version of WordPress. It is a light copy of the WordPress.com. Using this feature, you can create multiple WordPress website hosted at either separate directories or sub-domains (hosting on separate domains is not implemented yet). All the websites share same installation and so same themes and plugins. Plugins are activated globally through Network menu or through website’s plugin menu. But, If you want to disable one or more plugins in one or more of your websites, you can use following snippet to do it without using any plugin. It is very handy for the installations where root website has different layout than the other websites.

Snippet:

add_filter('site_option_active_sitewide_plugins', 'disable_network_plugins');

function disable_network_plugins($plugins) {
    global $current_blog;

    // Check if the current blog ID is "2"
    if( in_array($current_blog->blog_id, array(2)) ) {
        // disable akismet plugin
        unset($plugins['akismet/akismet.php']);
    }

    return $plugins;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>