Site logo

Archived topic

Only Load WP Show Post CSS On Home Page

3 replies · Started by Simon on March 20, 2019

Viewing posts 1–4 of 4

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

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 );

That seems to have worked perfectly. Thank you Tom.

You're welcome :)

This archived topic is closed to new replies.