[theme-reviewers] wp_enqueue_style

Chip Bennett chip at chipbennett.net
Fri Jun 3 11:33:51 UTC 2011


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).

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").

Chip

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.
>
>
>
>
> -----Original Message----- From: Otto
> Sent: Friday, June 03, 2011 4:17 AM
> To: theme-reviewers at lists.wordpress.org
>
> Subject: Re: [theme-reviewers] wp_enqueue_style
>
> On Fri, Jun 3, 2011 at 6:02 AM, Chip Bennett <chip at chipbennett.net> wrote:
>
>> Wait: you want to enqueue a *style* at 'wp_enqueue_scripts'? Or was that a
>> typo?
>>
>
> No, not a typo.
>
> There is no wp_enqueue_styles action hook, but if there was, then it
> would be at the same time/place that the existing wp_enqueue_scripts
> action hook is.
>
> The reason to enqueue at that time is because that gives the rest of
> the code time to potentially dequeue the script/style before it
> prints. If you wait until wp_print_styles to enqueue, then the only
> way you can possibly dequeue is to hook to wp_print_styles again with
> a larger priority number, which is annoying and weird.
>
> Again, enqueue early, dequeue late.
>
> Styles and scripts destined for the front end of the site should both
> be hooked into the wp_enqueue_scripts action hook.
>
> -Otto
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
> _______________________________________________
> 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/20110603/49605d7b/attachment.htm>


More information about the theme-reviewers mailing list