Many public pages in WordPress can be posts (e.g. the articles from the blog), pages (e.g. contact, about, terms), or custom post type pages such as the WooCommerce product pages which belong to the “product” post type. Let’s suppose you’re using WooCommerce and you know for sure that a plugin is loading CSS/JS files that are never needed on any product page. You can navigate to the targeted enqueued asset and use the following option: Unload CSS on all WooCommerce “Product” pages – just like the print screen below:

The same works for posts, pages, or custom post types. You might want to prevent an asset from loading on all the articles from your blog (e.g. it could be an asset that is meant to load only on pages such as “About us” or “Contact”).

What if I want to unload an asset site-wide (everywhere), but ONLY keep it loaded on all pages of a certain post type?

Let’s suppose you’re using WooCommerce and on the product page, there’s a gallery that works as a lightbox when clicked to navigate through the images. You know that the CSS/JS for that lightbox is never used on other pages and you only need it on every product page or most of the product pages. In this case, the most effective solution is to first unload the asset site-wide and make an exception to have it loaded on all product pages just like in the print screen below (you can click on the image to view it larger):

Was this post helpful?