Skip to content

Instantly share code, notes, and snippets.

@siaeb
Last active February 12, 2023 08:40
Show Gist options
  • Save siaeb/d0a238fc3ba4060bf4201ce582bb332d to your computer and use it in GitHub Desktop.
Save siaeb/d0a238fc3ba4060bf4201ce582bb332d to your computer and use it in GitHub Desktop.

Revisions

  1. siaeb revised this gist Jun 23, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion woocommerce_scripts_cleaner.php
    Original file line number Diff line number Diff line change
    @@ -45,4 +45,4 @@ function woo_scripts_cleaner() {

    }
    }
    add_action( 'wp_enqueue_scripts', 'woo_scripts_cleaner', 15 );
    add_action( 'wp_enqueue_scripts', 'woo_scripts_cleaner', 99 );
  2. siaeb created this gist Jun 23, 2022.
    48 changes: 48 additions & 0 deletions woocommerce_scripts_cleaner.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    function woo_scripts_cleaner() {
    remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
    if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
    $woo_styles = [
    'woocommerce_frontend_styles',
    'woocommerce-general',
    'woocommerce-layout',
    'woocommerce-smallscreen',
    'woocommerce_fancybox_styles',
    'woocommerce_chosen_styles',
    'woocommerce_prettyPhoto_css',
    'select2'
    ];
    $woo_scripts = [
    'wc-add-payment-method',
    'wc-lost-password',
    'wc_price_slider',
    'wc-single-product',
    'wc-add-to-cart',
    'wc-cart-fragments',
    'wc-credit-card-form',
    'wc-checkout',
    'wc-add-to-cart-variation',
    'wc-single-product',
    'wc-cart',
    'wc-chosen',
    'woocommerce',
    'prettyPhoto',
    'prettyPhoto-init',
    'jquery-blockui',
    'jquery-placeholder',
    'jquery-payment',
    'jqueryui',
    'fancybox',
    'wcqi-js',
    ];
    // Dequeue Styles
    foreach ( $woo_styles as $style ) {
    wp_dequeue_style( $style );
    }
    // Dequeue scripts
    foreach ( $woo_scripts as $script ) {
    wp_dequeue_script( $script );
    }

    }
    }
    add_action( 'wp_enqueue_scripts', 'woo_scripts_cleaner', 15 );