This WordPress plugin snippet conditionally unloads WooCommerce assets on non-WooCommerce pages, helping to optimize the loading speed of your site. By default, WooCommerce can load its scripts and styles on every page, even if the page doesn’t need them. With this enhancement, WooCommerce assets will only load on WooCommerce-related pages, reducing unnecessary requests and improving performance.
- Checks if WooCommerce is active on your site.
- Unloads WooCommerce assets on non-WooCommerce pages.
- Improves website performance by reducing unnecessary asset loading.
- Copy the provided code into your theme's
functions.php
file or as a standalone plugin. - Navigate your website; WooCommerce assets will now load only on relevant pages.
After installing:
- WooCommerce assets will automatically be dequeued on non-WooCommerce pages.
- Visit any non-WooCommerce page on your site and inspect the source. You should no longer see WooCommerce scripts and styles loaded.
- Visit a WooCommerce-related page, like the shop, cart, or checkout, and you'll see that WooCommerce assets are properly loaded.
Feel free to fork this repository and contribute by submitting a pull request.
This code is available under the MIT License.
You can save this content to a README.md
file in the root directory of your GitHub repository. It will provide visitors with information about what the project does and how to use it.
You can contact [email protected] about Woocommerce and Wordpress developments, e-commerce and website building.
For more information about GrowthBX https://growthbx.com