• Resolved Josh

    (@jmccallweb)


    Is there a way (via code) to only load the plugin’s assets on certain pages? We only use the plugin for a single image on a rather large site, and I’d like to only load the assets for that one post.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Diana Burduja

    (@dianaburduja)

    Hello Josh,

    at the moment I can offer you a rather convoluted solution, which dequeues the scripts added by the plugin, then adds them again on your specific post with another script handle. See this PHP snippet. Replace the is_single( 'simple-post-with-images' ) part with the Conditional Tag matching your post.

    But this gave me the idea to add a filter to the next plugin’s version (which will be released in about 6 weeks) that would conditionally add the scripts only to specific pages. That would be a much better solution.

    Instead of waiting for the next release, you could patch the plugin with this patch (i.e. replace the line prefixed with “-” with the lines prefixed with “+” in the “image-zoooom.php” file), then add the following PHP snippet to your website:

    add_filter( 'wp_image_zoooom_load_scripts', function() {
    return is_single( 'simple-post-with-images' );
    } );

    When updating the plugin to the next version, the patch will be overwritten, but the filter will still work and the scripts will load only on the specific post.

    Thread Starter Josh

    (@jmccallweb)

    Thank you so much for your excellent response! Five star review incoming. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.