Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Last active January 28, 2022 10:42
Show Gist options
  • Save Asikur22/cd1d6fc16e40f7468cf5cc763ad643b0 to your computer and use it in GitHub Desktop.
Save Asikur22/cd1d6fc16e40f7468cf5cc763ad643b0 to your computer and use it in GitHub Desktop.
Remove WooCommerce Scripts & Styles on Other Page
/**
* Optimize WooCommerce Scripts
* Updated for WooCommerce 2.0+
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
function customizable_blogily_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' );
}
}
}
add_action( 'wp_enqueue_scripts', 'customizable_blogily_manage_woocommerce_styles', 99 );
/**
* Disable WP Embed & emoji's
*/
function disable_emojis_embed() {
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
wp_dequeue_script( 'wp-embed' );
remove_action( 'rest_api_init', 'wp_oembed_register_route' );
add_filter( 'embed_oembed_discover', '__return_false' );
remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
}
add_action( 'init', 'disable_emojis_embed' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment