WordPress.org

Ready to get started?Download WordPress

Forums

Meteor Slides
[resolved] Enqueue scripts and stylesheets only on pages/posts with a slideshow (5 posts)

  1. helgatheviking
    Member
    Posted 2 years ago #

    I think it'd be a good idea if the scripts and styles associated with meteor slideshows only were loaded on posts/pages that required them. I'd like to use it only on the home page so it doesn't need to load on every page. Yes I know I can conditionally dequeue the assests, but it makes sense to me to only load them when needed in the first place.

    http://wordpress.org/extend/plugins/meteor-slides/

  2. Josh Leuze
    Member
    Plugin Author

    Posted 2 years ago #

    That's a great idea and I will be updating to work like this in a future release when I decide on the best way to do it.

    For now, I would go one step beyond dequeuing the scripts, and remove the script actions entirely when they aren't needed. Check out this plugin for removing Meteor Slides scripts, that will load them on just the homepage, you could change the conditional tag if you need them elsewhere.

  3. helgatheviking
    Member
    Posted 2 years ago #

    i know that WP shortcodes now support wp_enqueue_script (gets queued in the footer). maybe that is something you can tap into by creating a shortcode (i know you have one)

    // [bartag foo="5"]
    function bartag_func( $atts ) {
    	extract( shortcode_atts( array(
    		'foo' => '0'
    	), $atts ) );
    
           wp_enqueue_script('meteor-script');
    
           return file_get_contents(locate_template("template-file-name.php"));
    }
    add_shortcode( 'bartag', 'bartag_func' );

    with the template tag being something like:

    function bartag_slideshow($id=0){
      echo do_shortcode('[bartag  foo="'.$id.'"]');
    }

    so then you'd end up with a template tag that worked similar to how you have it now: <?php bartag_slideshow(5); ?>

    thanks for the tip on the remove actions... saves me from having to dig through the code to see how the scripts were being added.

    cheers!

  4. Josh Leuze
    Member
    Plugin Author

    Posted 2 years ago #

    Yeah that's exactly how I want to do it, I'm hoping to get that working with the existing template tag, but we'll see!

  5. helgatheviking
    Member
    Posted 2 years ago #

    cool! good luck!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic