Wordpress Disable Plugin on Specific Pages/Posts

后端 未结 5 1100
醉话见心
醉话见心 2020-12-13 19:28

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

5条回答
  •  不思量自难忘°
    2020-12-13 20:05

    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.

提交回复
热议问题