Title: enqueue plugin js only when needed
Last modified: August 21, 2016

---

# enqueue plugin js only when needed

 *  Resolved [allm](https://wordpress.org/support/users/realblueorange/)
 * (@realblueorange)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/enqueue-plugin-js-only-when-needed/)
 * @cubecolour
    I see that you made an adjustment in version 1.0.2: enqueue plugin
   js only when needed.
 * This seems like a good idea, but I have a case where the page with a tabby is
   output to a transient (shortcodes expanded) each day, and the transient gets 
   output to the screen. It seems that the js is not enqueued on that page.
 * Any ideas how I can fix your enhancement for that specific page?
 * [https://wordpress.org/plugins/tabby-responsive-tabs/](https://wordpress.org/plugins/tabby-responsive-tabs/)

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

 *  Plugin Author [cubecolour](https://wordpress.org/support/users/numeeja/)
 * (@numeeja)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/enqueue-plugin-js-only-when-needed/#post-4693138)
 * Does deleting & regenerating the transient make any difference?
 * If not, you can to go back to version 1.0.1 from [http://wordpress.org/plugins/tabby-responsive-tabs/developers/](http://wordpress.org/plugins/tabby-responsive-tabs/developers/)–
   it might be worth changing the version number in the tabby-responsive-tabs.php
   to 9999 so it doesn’t update in future.
 * Apart from the fix to enqueue the js only when needed, the only other changes
   were in the css.
 *  Thread Starter [allm](https://wordpress.org/support/users/realblueorange/)
 * (@realblueorange)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/enqueue-plugin-js-only-when-needed/#post-4693142)
 * @cubecolour:
 * Thanks for your quick reply.
 * Deleting & regenerating makes no difference. I guess the plugin only enqueues
   the js when the tabby shortcode is on the page. In my case the shortcode isn’t
   there anymore (has been do_shortcode’d before storing in the transient), but 
   the js still needs enqueueing on that page for the tabs to appear.
 * I don’t think it is a good idea to go back to 1.0.1 and never update again…
 * I guess that not enqueueing the js when the shortcode is not on the page is a
   good idea in more than 99% of the cases. My case is just in that 1% category.
 * I’ll figure out a way to also enqueue the js on that particular page. I’ll have
   a look at your code and implement some sort of workaround.
 *  Plugin Author [cubecolour](https://wordpress.org/support/users/numeeja/)
 * (@numeeja)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/enqueue-plugin-js-only-when-needed/#post-4693161)
 * Try adding the following to your child theme’s functions.php or custom functions
   plugin if you’re using one
 *     ```
       function cc_tabby_js() {
       	wp_enqueue_script( 'tabby', plugins_url('/tabby-responsive-tabs/js/tabby.js'), array('jquery'), '1.0.0', true );
       }
       add_action('wp_enqueue_scripts', 'cc_tabby_js');
       ```
   
 *  Thread Starter [allm](https://wordpress.org/support/users/realblueorange/)
 * (@realblueorange)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/enqueue-plugin-js-only-when-needed/#post-4693239)
 * @cubecolour
    Thanks for your suggestion. I added it to my child theme and everything
   worked again. Then I tried modifying it so it only loaded on the one page where
   it is needed.
 * Furthermore I checked the source code of your plugin to see if I could come up
   with an even more generic solution.
 * In the process I suddenly found out that after deleting the transient & regenerating
   it it should all work, just as you suggested. And it did. I thought I had tried
   that before I reacted earlier, but shame on me I apparently did not.
 * So after all, I do not need to change anything. I just need to be careful when
   you come out with a new version of the plugin. In that case I need to regenerate
   the transient (which I already do once a day automatically).
 * So, everything is solved on my end. I’ll set this thread to resolved.
 * Thanks for looking into this. Really appreciate it.
    I already gave a 5-star 
   review. If I could I would do it again!

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

The topic ‘enqueue plugin js only when needed’ is closed to new replies.

 * ![](https://ps.w.org/tabby-responsive-tabs/assets/icon-256x256.jpg?rev=2682041)
 * [Tabby Responsive Tabs](https://wordpress.org/plugins/tabby-responsive-tabs/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tabby-responsive-tabs/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tabby-responsive-tabs/)
 * [Active Topics](https://wordpress.org/support/plugin/tabby-responsive-tabs/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tabby-responsive-tabs/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tabby-responsive-tabs/reviews/)

## Tags

 * [enqueue](https://wordpress.org/support/topic-tag/enqueue/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 4 replies
 * 2 participants
 * Last reply from: [allm](https://wordpress.org/support/users/realblueorange/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/enqueue-plugin-js-only-when-needed/#post-4693239)
 * Status: resolved