Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mathetos/9867874 to your computer and use it in GitHub Desktop.
Save mathetos/9867874 to your computer and use it in GitHub Desktop.
<?php
/**
* Optimize WooCommerce Scripts
* Updated for WooCommerce 2.0+
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
//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_style( 'wc-bto-styles' ); //Composites Styles
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' );
}
}
}
remove_action('wp_head', 'wc_generator_tag');
@JordanMG
Copy link

What do you mean, @navjotjsingh? It seems to be removed from my pages with this gist, and inserted on the store pages as expected.

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