Wordpress Disable Plugin on Specific Pages/Posts

2020-02-08 04:07发布

问题:

Does anyone know a really effective method for disabling a plugin (that is active) on a specific page? There are some plugins that are not really needed in some pages of the website and they have lot of CSS and JavaScript files that are slowing the loading speed of the website and sometimes might conflict with other files.

I know that I can mess with the plugin's code etc. but it's not really effective.

Any ideas?

Thanks in advance!

回答1:

try "Plugin Organizer" Wordpress plugin by Jeff Sterup. You have to enable "Selective Plugin Loading" under it's settings (make sure to follow their directions given for enabling it)

Then in your post/page editor there is a box below the compose window with tickboxes to disable whichever particular plugin for that page

took me probably 20+ Google and Wordpress plugins repository searches to finally find a simple solution. Hope it works for you too!



回答2:

Here is the idea.

 add_filter( 'option_active_plugins', 'lg_disable_cart66_plugin' );

 function lg_disable_cart66_plugin($plugins){

      if(strpos($_SERVER['REQUEST_URI'], '/store/') === FALSE AND strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === FALSE) {
         $key = array_search( 'cart66/cart66.php' , $plugins );
         if ( false !== $key ) unset( $plugins[$key] );
      }

     return $plugins;
 }


回答3:

I know it's old but this thread was exactly what I needed.

The only caveat to numediaweb's answer is that remove action requires the same priority as the add action

Hooks in the plugin

add_action('wp_print_styles', 'easy_fancybox_enqueue_styles', 999);
add_action('wp_enqueue_scripts', 'easy_fancybox_enqueue_scripts', 999);
add_action('wp_head', 'easy_fancybox', 999);

Code to remove hooks

function remove_easy_fancybox() {

     global $post;
     $ids = array(12,34,55);
     if(in_array($post->ID,$ids)):
          remove_action('wp_print_styles', 'easy_fancybox_enqueue_styles', 999);
          remove_action('wp_enqueue_scripts', 'easy_fancybox_enqueue_scripts',999);
          remove_action('wp_head', 'easy_fancybox', 999);

          wp_dequeue_script( 'jquery.fancybox' );
          wp_dequeue_script( 'jquery.easing' );
          wp_dequeue_script( 'jquery.mousewheel' );
          wp_dequeue_script( 'jquery.metadata' );
     endif;
}

add_action('wp_head', 'remove_easy_fancybox', 1);

From http://codex.wordpress.org/Function_Reference/remove_action

Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.

I've included my if statement to only run the action on specific post ids, thought it might be helpful.



回答4:

First check, if the plugin you want to remove doesn't have an option menu where you set pages to exclude.

Second is, look for your plugin action hooks for ex:

add_action('wp_head', 'easy_fancybox', 999);

This is an example from easy fancybox plugin that hooks to wordpress header. To remove it, I placed this function in your functions.php and before any instance of wp_head(); is called:

function remove_easy_fancybox() {

     remove_action('wp_head', 'easy_fancybox_enqueue_styles');
     remove_action('wp_head', 'easy_fancybox_enqueue_scripts');
     remove_action('wp_head', 'easy_fancybox');

     wp_dequeue_script( 'jquery.fancybox' );
     wp_dequeue_script( 'jquery.easing' );
     wp_dequeue_script( 'jquery.mousewheel' );
     wp_dequeue_script( 'jquery.metadata' );
}

add_action('wp_head', 'remove_easy_fancybox', 1);


回答5:

you can now use the free plugin Freesoul Deactivate Plugins to deactivate specific plugins on specific pages, posts, custom posts and archives, the settings page is really simple