Skip to content

Instantly share code, notes, and snippets.

@blogjunkie
Created June 24, 2014 03:55
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 blogjunkie/cfdab697c0dd3083f05c to your computer and use it in GitHub Desktop.
Save blogjunkie/cfdab697c0dd3083f05c to your computer and use it in GitHub Desktop.
Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages
<?php
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*
* @link http://wordimpress.com/how-to-load-woocommerce-scripts-and-styles-only-in-shop/
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//first check that woo exists to prevent fatal errors
if ( function_exists( 'is_woocommerce' ) ) {
//dequeue scripts and styles
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
wp_dequeue_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
wp_dequeue_style( 'woocommerce-general' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment