Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@amsgator
Created April 6, 2019 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amsgator/3ee5b9f94b86ec57792647d8fcba8b7a to your computer and use it in GitHub Desktop.
Save amsgator/3ee5b9f94b86ec57792647d8fcba8b7a to your computer and use it in GitHub Desktop.
Dequeue WooCommerce Scripts from Non-WooCommerce Pages / Posts
<?php
function dequeue_woo() {
if ( function_exists( 'is_woocommerce' ) ) {
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() && ! is_account_page() ) {
// Styles
wp_dequeue_style( 'woocommerce-general' );
wp_dequeue_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
// Scripts
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-cookie' );
wp_dequeue_script( 'woocommerce' );
}
}
}
add_action( 'wp_enqueue_scripts', 'dequeue_woo', 100 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment