Load WooCommerce Assets Only on Shop Pages
Stops WooCommerce stylesheets and scripts from loading on pages that are not part of the store, such as blog posts and the about page.
Opens WPIDE on
Code
add_action( 'wp_enqueue_scripts', function () {
if ( ! function_exists( 'is_woocommerce' ) ) {
return;
}
if ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) {
return;
}
foreach ( array( 'woocommerce-general', 'woocommerce-layout', 'woocommerce-smallscreen' ) as $handle ) {
wp_dequeue_style( $handle );
}
foreach ( array( 'wc-cart-fragments', 'woocommerce', 'wc-add-to-cart' ) as $handle ) {
wp_dequeue_script( $handle );
}
}, 99 );
Notes
Do not use this if non-shop pages show products, a mini cart or add-to-cart buttons.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.