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

Andrew Ozz admin at laptoptips.ca
Fri May 2 18:19:01 GMT 2008


Alexander Beutl wrote:
> 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.

Could try using get_footer() (not wp_footer() that's missing from a lot 
of themes), as all of the js effects scripts run "on dom loaded" and can 
be included just above the </body> tag. Then you could check for all 
scripts included in the header and all calls coming from templates and 
shortcodes.


More information about the wp-hackers mailing list