Skip to content

Commit a8c4ecb

Browse files
Create unload-js-css-files
to stop loading woocommerce css and js file on non woocommerce page
1 parent 51951d9 commit a8c4ecb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

unload-js-css-files

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
func/*
2+
* add this function in your theme function.php file or in your child theme function.php
3+
* this will stop woocommerce css and js file to load on non woocommerce page if woocommerce is active
4+
*/
5+
add_action( 'wp_enqueue_scripts', 'stop_woocommerce_loading_css_js' );
6+
7+
function stop_woocommerce_loading_css_js() {
8+
9+
// Check if WooCommerce plugin is active
10+
if( function_exists( 'is_woocommerce' ) ){
11+
12+
// Check cuurent page is WooCommerce page or not
13+
if(! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
14+
15+
## Dequeue WooCommerce styles
16+
wp_dequeue_style('woocommerce-layout');
17+
wp_dequeue_style('woocommerce-general');
18+
wp_dequeue_style('woocommerce-smallscreen');
19+
20+
## Dequeue WooCommerce scripts
21+
wp_dequeue_script('wc-cart-fragments');
22+
wp_dequeue_script('woocommerce');
23+
wp_dequeue_script('wc-add-to-cart');
24+
25+
wp_deregister_script( 'js-cookie' );
26+
wp_dequeue_script( 'js-cookie' );
27+
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)