WordPress can’t dequeue style

I’m trying to get rid of unused styles in my WP. I’m doing it like this:

// remove CSS
add_action('wp_dequeue_style', 'remove_css');

function remove_css() {
    // boostrap shortcodes
    wp_dequeue_style(array(
        'bs_bootstrap-css',
        'bs_shortcodes-css'
    ));

    // woocommerce
    wp_dequeue_style('woocommerce-layout-css');
    wp_dequeue_style('woocommerce-smallscreen-css');
    wp_dequeue_style('woocommerce-general-css');
}

Problem is, neither first nor the secound example works. I tried using wp_deregister_script and setting a priority to add_action. What can I do?

Related posts

Leave a Reply

2 comments

  1. You should hook into wp_enqueue_scripts:

    add_action( 'wp_enqueue_scripts', 'so26892641_remove_css', 25 );
    function so26892641_remove_css(){
        wp_dequeue_style('woocommerce-layout');
        // etc
    }
    
  2. Woocommerce has a filter for that, also note that the handles do not have “-css” at the end.

    add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
    
    function jk_dequeue_styles( $enqueue_styles ) {
        unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
        unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
        unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
        return $enqueue_styles;
    }
    

    Code shamelessly copied from the following link 🙂