[wp-hackers] wp_enqueue_script() and URLs with 2+ parameters
Glenn Ansley
glenn at glennansley.com
Fri Feb 27 20:20:01 GMT 2009
>> 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.
function testers(){
global $wp_query;
if ( 4 == $wp_query->query_vars['page_id'] ) :
echo "Ta da!";
endif;
}
add_action('template_redirect','testers');
// assuming 4 is the page you're looking for... or you could do
in_array() for mulitple pages, or use the p variable, etc
Glenn Ansley
WordPress Pluign Development
http://fullthrottledevelopment.com
On Fri, Feb 27, 2009 at 3:05 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> "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/
> _______________________________________________
> 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