[theme-reviewers] Hooking wp_enqueue_script( 'comment-reply' ) into wp_head
Chip Bennett
chip at chipbennett.net
Thu Apr 21 19:50:55 UTC 2011
Now, why didn't that work for me before?
I probably had a brain fart, and tried to use 'wp_enqueue_styles' instead of
'wp_enqueue_scripts'.
So, yeah: what Otto said. :)
Here would be the correct function:
function oenology_enqueue_comment_reply() {
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
{
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'oenology_enqueue_comment_reply' );
Chip
On Thu, Apr 21, 2011 at 2:21 PM, Otto <otto at ottodestruct.com> wrote:
> 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
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110421/a8dd1d9f/attachment.htm>
More information about the theme-reviewers
mailing list