[Resolved] Only Load WP Show Post CSS On Home Page

Home Forums Support [Resolved] Only Load WP Show Post CSS On Home Page

Home Forums Support Only Load WP Show Post CSS On Home Page

  • This topic has 3 replies, 2 voices, and was last updated 4 years ago by Tom.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #844902
    Simon

    Hey,

    If there is not a super quick solution to this please feel free to just ignore it.

    I am now using WP Show Post (awesome plugin by the way Tommo) however I am just using it on the home page and noticed that it loads the CSS for it on every page?

    I am guessing you guys could come up with some of that code trickery to get it to only load on the home page? thus speeding up my other couple hundred posts.

    Cheers,
    Simon

    GeneratePress 2.2.2
    GP Premium 1.7.8
    #845050
    Tom
    Lead Developer
    Lead Developer

    Hey Simon,

    WordPress doesn’t allow us to only add CSS files if a shortcode exists on a page, unless we want it to load in the footer.

    If you know for sure you only need it on the home page, you can do this:

    add_action( 'wp_enqueue_scripts', function() {
        if ( ! is_front_page() ) {
            wp_dequeue_style( 'wp-show-posts' );
        }
    }, 20 );
    #845328
    Simon

    That seems to have worked perfectly. Thank you Tom.

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