[theme-reviewers] Hooking wp_enqueue_script( 'comment-reply' ) into wp_head

Otto otto at ottodestruct.com
Thu Apr 21 19:21:52 UTC 2011


On Thu, Apr 21, 2011 at 1:44 PM, Chip Bennett <chip at chipbennett.net> wrote:
> Most Themes drop the wp_enqueue_script( 'comment-reply' ) code directly into
> the document head, but it *can* be hooked into wp_head, if given the correct
> priority.
> I *think* wp_enqueue_styles fires at priority 1 in wp_head. Regardless,
> passing priority 0 to the enqueue function *does* work. e.g.:

There is no "wp_enqueue_styles". There is wp_enqueue_scripts, and you
should hook it to that action, for future proofing.

add_action( 'wp_enqueue_scripts', 'oenology_enqueue_comment_reply' );

The wp_enqueue_scripts action runs from the wp_enqueue_scripts
function, which itself is hooked to wp_head with priority 1. This
makes enqueueing happen before script output does later. The reason
for this future-proofing is because of the existence of the
wp_enqueue_scripts() function itself, which may not always just be
calling an action hook like it does now.

*Always* enqueue scripts on the wp_enqueue_scripts action. That's what
it's there for.

-Otto


More information about the theme-reviewers mailing list