Categories: DevelopmentWordPress

Speed up WordPress / WooCommerce on none commerce pages

WooCommerce provides great functionality, but loads a lot of resources even if not needed.

If a site loads longer than 5-7 seconds, potential customers already loose interest :)

UNLOAD ALL THAT IS NOT NEEDED

Add this to your functions.php:

  1. add_action( 'wp_enqueue_scripts', 'cleanup_woocommerce_includes', 99 );
  2.  
  3. function cleanup_woocommerce_includes(){
  4.  //check that woo exists
  5.  if ( function_exists( 'is_woocommerce' ) ) {
  6.   if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {}
  7.   /*Styles*/
  8.   wp_dequeue_style( 'woocommerce_frontend_styles' );
  9.   wp_dequeue_style( 'woocommerce_fancybox_styles' );
  10.   wp_dequeue_style( 'woocommerce_chosen_styles' );
  11.   wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
  12.  
  13.   wp_dequeue_style( 'woocommerce-layout' );
  14.   wp_dequeue_style( 'woocommerce-smallscreen' );
  15.   wp_dequeue_style( 'woocommerce-general' );
  16.   wp_dequeue_style( 'wc-bto-styles' );         
  17.  
  18.  
  19.   /*Scripts*/
  20.   wp_dequeue_script( 'wc-cart' );
  21.   wp_dequeue_script( 'wc-cart-fragments' );
  22.   wp_deregister_script( 'wc-add-to-cart' );
  23.   wp_dequeue_script( 'wc-add-to-cart' );
  24.   wp_deregister_script( 'wc-add-to-cart-variation' );
  25.   wp_dequeue_script( 'wc-add-to-cart-variation' );
  26.   wp_dequeue_script( 'wc-checkout' );
  27.  
  28.   wp_dequeue_script( 'wc-single-product' );
  29.   wp_dequeue_script( 'jquery-blockui' );
  30.   wp_dequeue_script( 'wc_price_slider' );              
  31.  
  32.   wp_dequeue_script( 'wc-chosen' );
  33.   wp_dequeue_script( 'woocommerce' );
  34.   wp_dequeue_script( 'prettyPhoto' );
  35.   wp_dequeue_script( 'prettyPhoto-init' );             
  36.   wp_dequeue_script( 'jquery-placeholder' );
  37.   wp_dequeue_script( 'fancybox' );
  38.   wp_dequeue_script( 'jqueryui' );
  39.  
  40.   }
  41.  }
  42. }

Like always, make sure that nothing breaks. If things break or are required by certain pages add an exception for that!

Check WordPress Condional Tags.

Sources:

  1. How to Load WooCommerce Scripts and Styles Conditionally to Improve Page Load Speed
  2. Only load WooCommerce scripts on shop pages and checkout + cart

REMOVE GENERATOR META TAG

  1. remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
  2. remove_action('wp_head', 'wc_generator_tag');
  3.  

Enjoy coding …

Alex

I am a full-stack developer. I love programming,  design and know my way around server architecture as well.  I would never feel complete, with one of these missing. I have a broad range of interests, that’s why I constantly dive into new technologies and expand my knowledge where ever required. Technologies are evolving fast and I enjoy using the latest. Apart from that, I am a peace loving guy who tries to have people around him that think the same.  I truly believe in the principle: “If you help someone, someone will help you, when you need it."

Recent Posts

Particle Network Animations in Javascript

What are particle animations? Particle network animations in JavaScript typically involve creating visual representations of… Read More

5 days ago

B&B / Hotel Booking Solutions for WordPress | 2024

BOOKING SOLUTIONS 202x This is my take on a subset of booking, appointment, PMS or… Read More

1 month ago

WordPress Cron + WP-CLI + Ntfy

THE GOAL Create a system cron for WordPress, that is accessible and can be easily… Read More

3 months ago

2024 is here and now :)

2024, what's cooking? Slowly getting into the 2024 spirit. 3 projects coming to a close… Read More

4 months ago

2023 ends and whats next !

Short look back at 2023 This has been a busy and interesting year. I am… Read More

4 months ago

cubicFUSION Grid Tweaker – Elementor Grid made easy.

Elementor Pro provides grid containers as an experimental feature. The options provided are limited, when… Read More

5 months ago