[wp-hackers] Adding JS to a Page based upon the used shortcodes

Alexander Beutl xel at netgra.de
Fri May 2 14:03:09 GMT 2008


Thanks Casey and Otto,
that seems to do the trick at least for "standard templates" with only a
single loop.

the only remaining thing is:
I will also need to know which methods are used inside the template - but
there I may aks the user to specify which scripts should be enqueued on each
page load because they are used in template... (I think this is still better
then scanning all template files which would be an enormous performance
waste).

Maybe I will add a fallback to add the script in body when it wasn't added
to head allready since this is still better than if it's missing.


2008/5/2 Otto <otto at ottodestruct.com>:

> Yes, you could wait as long as the wp_print_scripts action before
> enqueuing your script, but that's it. You'll have to manually search
> the post content for the shortcodes.
>
> On Fri, May 2, 2008 at 8:06 AM, Casey Bisson <casey.bisson at gmail.com>
> wrote:
> >
> >  I haven't checked this in 2.5, but I believe you could hook into
> > template_redirect. The posts have been queried, but nothing has been
> output
> > to the browser at that point. You could sniff the content and add
> > wp_enqueue_script hooks then.
> >
> >  http://wphooks.flatearth.org/hooks/template_redirect/
> >
> >
> >
> >
> >  On May 2, 2008, at 7:13 AM, Alexander Beutl wrote:
> >
> >
> > > Hi,
> > >
> > > I am working on an image gallerie plugin using the new shortcodes and
> I
> > want
> > > to add some options to define
> > > a) how the gallerie should look
> > > b) which JS is used (thickbox, lytebox, jQuery Lightbox, and some
> others,
> > > which will do really different things like slideshows, flash like
> > galleries,
> > > carousels and stuff)
> > >
> > > While I could make this be defined consistantly between all pages when
> > using
> > > options, I want to make it costomizable per Post (or per Gallerie I
> should
> > > say, since one could use more then one gallerie and one could use a
> > gallerie
> > > in template) using attributes in the shortcodes.
> > >
> > > I know about the wp_enqueue_script command but this doesn't work when
> > called
> > > inside the shortcode function since this is much to late (head is out
> > > allready) - and I do not know about any functionality how to know
> about
> > the
> > > used shortcodes before I am in the shortcode function. Is there any
> way to
> > > do this?
> > >
> > > Yes maybe it would work to write the JS directly into the body but
> this
> > > isn't a good solution. Any ideas?
> > >
> > > Thanks
> > > Alex
> > > _______________________________________________
> > > wp-hackers mailing list
> > > wp-hackers at lists.automattic.com
> > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > >
> >
> >  _______________________________________________
> >  wp-hackers mailing list
> >  wp-hackers at lists.automattic.com
> >  http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list