[theme-reviewers] wp_enqueue_style

Andrew Nacin wp at andrewnacin.com
Sat Jun 4 00:49:09 UTC 2011


Given the ongoing confusion, let me try to clear some things up.

First, Otto is correct in everything I've read. wp_enqueue_scripts is the
right hook on which one calls wp_enqueue_script() and wp_enqueue_style().
The wp_print_styles hook is too late.

The init hook is also poor form. Don't use it. This is wrong. This will then
enqueue the style/script for the admin. Do not do an is_admin() check. That
will keep it enqueued for wp-login. Do not do a $pagenow = 'wp-login.php'
check. That is just silly. Use the right hook.

template_redirect is not technically too early -- it's, I would say, the
earliest possible hook to ever use here -- but again, if you *are* going to
attach it to a hook, use the right hook (wp_enqueue_scripts).

If you are not going to attach it to a hook, then your only choice is in the
body of header.php, as long as it is before wp_head(). Anywhere else I would
consider wrong.

As Mike Little said, enqueueing too early *can* break things. Specifically
localization. Ideally we should start to fire _doing_it_wrong() notices
whenever wp_enqueue_scripts is enqueued before template_redirect (give or
take).

Hope that helps. Anything else to clear up?

Nacin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110603/b74a0df0/attachment.htm>


More information about the theme-reviewers mailing list