[Support request] Load CSS file only if element with class is present on the page

Home Forums Support [Support request] Load CSS file only if element with class is present on the page

Home Forums Support Load CSS file only if element with class is present on the page

  • This topic has 3 replies, 3 voices, and was last updated 1 month ago by Ying.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2280443
    Rostyslav

    Hello,

    I use a Customizer to add aditional CSS (id=”wp-custom-css”). The problem is all that css is loading in all pages. Is there any way to load it dynamically? Load CSS file only if element with class is present in that particular page.

    Thank!

    #2280466
    David
    Staff
    Customer Support

    Hi there,

    do you want to only load wp-custom-css if there is a specific class?
    and if there is no class DO NOT load wp-custom-css

    #2280698
    Rostyslav

    No. The customizer’s CSS is loading in all my pages. It is loading all CSS even if some styles are not effecting that specific page.

    How can I load just part of that CSS that affects the specific page instead of loading all custom CSS of all pages.

    #2280818
    Ying
    Staff
    Customer Support

    How can I load just part of that CSS that affects the specific page instead of loading all custom CSS of all pages.

    I don’t think there’s an easy way to achieve this.

    If you want, you can use the hook element, wrap the CSS specifically for some pages like this <style>your css</style> , and hook it into the wp_head, assign it to those pages.

    But in this way, it’s not easy to manage all your CSS.

    I checked your CSS file, there’re not many codes in it, I don’t think you need to worry about this.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.