Forked from DevinWalker/woocommerce-optimize-scripts.php
Last active
June 26, 2022 15:28
-
-
Save mathetos/9867874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
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
There is some issue here. jquery-blockui cannot be just unqueued. It needs to be deregistered.