Skip to content

Instantly share code, notes, and snippets.

@gregrickaby
Last active November 26, 2024 23:20
Show Gist options
  • Save gregrickaby/2846416 to your computer and use it in GitHub Desktop.
Save gregrickaby/2846416 to your computer and use it in GitHub Desktop.
Remove WooCommerce styles and scripts.
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
/**
* Remove WooCommerce Generator tag, styles, and scripts from the homepage.
* Tested and works with WooCommerce 2.0+
*
* @author Greg Rickaby
* @since 2.0.0
*/
function child_manage_woocommerce_styles() {
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
if ( is_front_page() || is_home() ) {
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_style( 'woocommerce_fancybox_styles' );
wp_dequeue_style( 'woocommerce_chosen_styles' );
wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
wp_dequeue_script( 'wc_price_slider' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-add-to-cart-variation' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-chosen' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'prettyPhoto' );
wp_dequeue_script( 'prettyPhoto-init' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
wp_dequeue_script( 'fancybox' );
wp_dequeue_script( 'jqueryui' );
}}
@yupii1986
Copy link

Hi,
Is working with woocommerce 2.4?
do you have any code for minify js and css automaticly in wordpress? Or reduce number of js/css without plugins?

Thank you

@jfbuildstuff
Copy link

Super helpful, thanks!

@landsman
Copy link

landsman commented Aug 1, 2016

Not working with WooCommerce 2.6.4

@pixeline
Copy link

simply deregister jquery is another, more radical way to go :)

wp_deregister_script('jquery');

@alvinkonda
Copy link

Thanks...

@ikhsanalatsary
Copy link

Not working with WooCommerce 2.6.4

@cassianotartari
Copy link

cassianotartari commented Oct 26, 2016

I removed right now some css files using this:

function woocommerce_dequeue_styles( $enqueue_styles ) {
    if ( !is_woocommerce() && !is_cart() && !is_checkout() ) {
        unset( $enqueue_styles['woocommerce-general'] );
        unset( $enqueue_styles['woocommerce-layout'] );
        unset( $enqueue_styles['woocommerce-smallscreen'] );
    }
    return $enqueue_styles;
}
add_filter( 'woocommerce_enqueue_styles', 'woocommerce_dequeue_styles' );

Is in documentation, check it out.

@littlepackage
Copy link

FWIW the WP 5+ Gutenberg block CSS handle is 'wc-block-style'

@rohitsavaj
Copy link

littlepackage

FWIW the WP 5+ Gutenberg block CSS handle is
twentysixteen-block-style

@87percentrum
Copy link

add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment