We can now write a function using these handles to block these scripts from loading when not required. In our case, the plugin handles we are looking for are woocommerce, wc-add-to-cart and wc-cart-fragments. styles applyfilters ( 'woocommerceenqueuestyles', array ( 'woocommerce-layout' > array ( 'src' > self::getasseturl ( 'assets/css/woocommerce-layout.css' ), 'deps. woocommerce/includes/class-wc-frontend-scripts.php 67-99. Use a software like notepad++ to conduct the search and find. WCFrontendScripts::getstyles () woocommerceenqueuestyles. You can find these handles by digging into the plugin files and searching for the terms self::enqueue_script and self::register_script. These functions require you to provide the handles of scripts that need to be dequeued. These functions dequeue any scripts or styles that are enqueued by wordpress. Therefore it is always a good practice to restrict plugins from unnecessarily loading JS and CSS files where not required.įor WooCommerce, you can easily achieve this by using the wp_dequeue_script() and wp_dequeue_style() wordpress functions. The more files the server has to request while rendering a page, the more time it takes to load. In other words, these files are loaded on regular pages that do not require these styles and scripts to function.Īs you must be aware, it is a good practice to keep the number of CSS and JS references on a page to the bare minimum as this can impact page load speed. Templates render inside the content, and this keeps everything looking natural on your site. The issue is that these files load on all wordpress posts and pages irrespective of if or not the page is a WooCommerce page. WooCommerce Theme Developer Handbook WooCommerce looks great with all WordPress themes as of version 3.3, even if they are not WooCommerce-specific themes and do not formally declare support. As of the latest 2021 version which is 4.5.2 at the time of writing this article, five stylesheets and five Javascript files are enqueued on all pages (site wide) as follows: Some of these files are added only to the product, shopping cart and checkout pages, where as a few others are added sitewide. After installation, Woocommerce (version 4.5.2) by default enqueues many CSS and JS files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |