I want to disable some plugins from a specific theme.I am using deactivate_plugins hook to deactivate. following is my code.

function disable_plugins(){
    $current_theme = wp_get_theme();
    $current_theme_name = $current_theme->Name;

    if($current_theme_name == 'Twenty Sixteen'){
        if ( is_plugin_active('press-release/init.php') ) {

This code deactivate plugins at wp_head hook but issue is I want active plugins to disable only when theme is Twenty Sixteen while wants to keep enable or disable as it was already on other themes.

But my code deactivates plugins for all themes. :(

Other solution was of deregistering css and js files of each plugin but its tough to find all css and js files for all plugins and it will also deregister for all themes while I want active plugins to disable on specific theme.

Please help me if you can in this case. Thanks.

  • Where did you put this code ? In a plugin ?
    – Sumit
    May 2 '16 at 10:16
  • @Sumit I am putting this code in theme's functions.php May 2 '16 at 10:26
  • @Sumit man when twenty sixteen is activated, this code deactivates plugin and once it is deactivated it means it is deactivated for all. Did you get this ?? May 2 '16 at 10:30
  • LOL! of course it will be deactivated till you re-active the plugin on switch theme hook ;) How will WordPress know that you want to activate the plugin again when theme is changed ?
    – Sumit
    May 2 '16 at 10:36
  • @Sumit of course, this is what my question is. I am not saying that my code is going to solve my issue. my question is how to achieve that goal ??? May 2 '16 at 10:49

What @Sumit says in the comments (and you found out for yourself) is correct. If you deactivate a plugin in a theme it is deactivated permanently, until it is activated again.

Also, if you attach your deactivation action to wp_head it is executed at every pageload, which is not necessary. What you need to do is deactivate the plugin when the theme is activated, and reactivate the plugin when another theme is activated. There are action hooks for this: after_switch_theme on activation and switch_theme on deactivation. So you would have:


You already have the disable_plugins function, the other one you'll need to write yourself.

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.