[theme-reviewers] wp_enqueue_script

Austin Matzko austin at pressedcode.com
Wed Sep 15 15:09:51 UTC 2010


On Wed, Sep 15, 2010 at 9:56 AM, Chip Bennett <chip at chipbennett.net> wrote:
> Hmm... I'm completely unfamiliar with the template_redirect hook - and, I
> thought enqueueing scripts was one of the uses of wp_head()? (Learning
> something new every day, I guess!)
> So, should I recommend hooking into template_redirect(), or wp_footer() - or
> either, or both?

template_redirect is the last action hook before the actual template
file is included and executed.

You could also use the wp_enqueue_scripts action hook to attach your
enqueuing callbacks; wp_enqueue_scripts is called early in wp_head.
However, I prefer template_redirect because it's late enough that WP
has parsed the request (so is_singular() and the like are available)
but it's prior to the actual template file's being included, so if the
theme queries posts on its own prior to that point I don't have to
worry about resetting $wp_query.

Whatever works for you, but default wp_head without a high priority is too late.


More information about the theme-reviewers mailing list