[wp-hackers] wp_enqueue_script() and URLs with 2+ parameters
Mike Schinkel
mikeschinkel at newclarity.net
Fri Feb 27 20:05:49 GMT 2009
"Nathan Rice" <ncrice at gmail.com> wrote:
> Why is it that, in order to use wp_enqueue_script in a theme,
> you have to hook it to wp_head? If I create my own action, and
> try to hook it to that, it won't work (at least, it won't work
> if you call that action before wp_head in your header.php file).
I've actually been thinking about this alot too, especially related to page templates. The obvious answer is that the header has already been generated by the time the code gets to the template.
However, I do think it would be incredibly helpful if it could be rethought, possibly with a plugin, that would allow the calls to wp_enqueue_script() and similar to be stored in the same file as page template that uses it, or at least a similarly named file. My current project needs this on tens of pages; for example I have a script that is specific to the video gallery page and is doen't need to be and probably shouldn't be included elsewhere.
What would be nice is, for example, if we could create a function in a page template called (something like) "init_template()" and have that function called during init() for a page template.
There are lots of issues with this approach, I realize, but they could be overcome in a plugin. One small thing that would be less-than-idal is that doing this would duplicate some significant logic in core such as the logic found in template-loader.php. It would be nice if the code in lines 17-59 were refactored into a function that returned the template file name so that logic could be used elsewhere. Would this be the type of thing appropriate to add a ticket into track for?
-Mike Schinkel
http://mikeschinkel.com/
More information about the wp-hackers
mailing list