[theme-reviewers] wp_enqueue_style

Otto otto at ottodestruct.com
Fri Jun 3 11:49:24 UTC 2011


On Fri, Jun 3, 2011 at 6:27 AM, Chip Bennett <chip at chipbennett.net> wrote:
> I don't understand why using priority numbers, for their intended purpose,
> is "annoying" or "weird"?

It's weird because using priorities in this manner requires the use of
"magic" numbers, basically. Priorities aren't defined. Names of hooks
are and run in a specific order.

> I'm all for recommending best practice, whatever that may be; I'm just
> surprised that until now we've not heard anyone suggest this method,
> although we've been discussing style enqueueing for almost a year.

Well, nobody asked me, or I'd have told 'em before. :)

On Fri, Jun 3, 2011 at 6:27 AM, Philip M. Hofer (Frumph)
<philip at frumph.net> wrote:
> Otto, it shouldn't make a difference (entirely)* when you hook it in,
> because the wp action for the wp_enqueue places it in the process at the
> appropriate time regardless. * Entirely - meaning of course use a close
> approximation for the triggering of it, after_page_load would be just a bit
> off.
>
> You could do it at 'init' with everything else and it will still process it
> in the enqueue at the appropriate place - you just don’t want to hook it
> into the print because by that time it's a little late in the game and
> should be used for dequeue.
>
> I would actually recommend putting wp_enqueue_(script/style) in the themes
> init location; whether it uses init or some other action location at that
> time it's best to do it when the theme itself is triggering of registered
> variables that are used throughout the theme instead of intensifying the
> codes confusion.

Agreed, hooking earlier is fine. It's hooking in too late that is the
issue. wp_print_styles is just really, really late in the process.

On Fri, Jun 3, 2011 at 6:33 AM, Chip Bennett <chip at chipbennett.net> wrote:
> I seem to remember running into a problem where a registered style was
> enqueued and hooked into 'wp_enqueue_styles', but the link never printed
> (which IIRC, was where the original recommendation - from Nacin, perhaps? -
> to use 'wp_print_styles' came from).

There is no wp_enqueue_styles hook or anything similar to it, which is
probably where the original issue came from.

It's just that wp_print_styles is the absolute last moment that you
can enqueue a style. Enqueueing earlier is better.

> It would be good to have a recommended implementation - e.g. "ideally, hook
> in to *this* hook, but in any case, hook in no sooner than *this* hook, but
> also no later than *this* hook" (that is, if we can't just settle on a given
> hook, to say "enqueue styles on *this* hook, period").

Here's the way it should be:

Enqueue scripts or styles at wp_enqueue_scripts or earlier (but not
before the init hook).
Dequeue scripts at wp_print_scripts.
Dequeue styles at wp_print_styles.

-Otto


More information about the theme-reviewers mailing list