![]() Here’s what that type of file might look like. You can include this code directly in the functions.php file of your theme, but I generally load a separate file as a class either from a mu-plugin or the theme. I’ve limited the dequeues to the front page of the site in these code blocks, but you can use different page conditionals to remove the scripts and styles from where they are not needed. ![]() Wp_dequeue_style( 'woocommerce-inline' ) Īdd_action( 'wp_enqueue_scripts', 'prefix_remove_styles', 100 ) Wp_dequeue_style( 'wc-block-vendors-style' ) * Remove styles that have been enqueued by other plugins. To dequeue styles you can use the wp_enqueue_scripts hook: /** plugindirurl () - Get URL for the plugin directory. enqueue script won't work (enqueue style does work) How to enqueue style before style.css wp enqueue style and style sheet depth i uploaded a custom theme on wordpress but its style is not working i cannot enqueue the style Style.css not overwriting parent style.css although style.css and functions.php are set up Enqueue style for specific site. ispage () - Condition to check if you want to load the JS on specific pages only. Wp_dequeue_script( 'storefront-header-cart' ) Īdd_action( 'wp_print_scripts', 'prefix_remove_scripts', 100 ) wpenqueuescript () - Used to actually enqueue the script wplocalizescript () - Used to pass any variables/data from WordPress/PHP to JS gettemplatedirectoryuri () - Retrieve theme directory URI. Wp_dequeue_script( 'wc-cart-fragments' ) * Remove scripts that have been enqueued by other plugins. To dequeue scripts you can use the wp_print_scripts hook. In other words, WordPress should load the CSS styles found in. The gettemplatedirectoryuri () part specifies where style.css is located: it’s in the main folder of the parent theme. ![]() Specifically, it tells WordPress to use the stylesheet called style.css. It will also show you the “handle”, which is needed to dequeue the asset. The function mychildthemeenqueuestyles () activates the parent theme’s CSS styles. Query monitor will show you all the scripts enqueued by WordPress for a specific page. Screenshot of site with Query Monitor running This will let you know which scripts and styles are enqueued for a specific page. To find our which scripts and styles are enqueued, you’ll need to do a some detective work. I recently went on a performance rampage at Universal Yums and removed ~300kb of enqueued assets that were not needed on our home page- which shows there can be quite a bit of fat to trim. For example, WooCommerce loads at least 3 scripts and 4 styles on every page, even if ecommerce functionality (like a cart or products) aren’t shown on those pages. Many WordPress plugins load scripts and styles on every page of a website even though they may just be needed on a few specific pages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |