[theme-reviewers] html5.js enqueuing

Otto otto at ottodestruct.com
Thu Jun 13 06:00:23 UTC 2013


On Thu, Jun 13, 2013 at 12:44 AM, Paul Appleyard <paul at spacecat.com> wrote:
> I've run up against reviewers who insist that all scripts and stylesheets
> MUST be enqueued with a callback - as indeed the guidelines state. However,
> the comment reply JS is enqueued without callback in the header of
> TwentyTwelve and is considered the de-facto way to enqueue that.
>
> So, what is the exception? Is there something in the way that WordPress
> loads templates and functionality that obviates the use of one style over
> the other?
>
> Paul Appleyard

If you *can* enqueue it in a callback, you should always do so. The
enqueue system gives greater flexibility to child themes for adjusting
things.

However, as stated, the need for IE conditionals around scripts (not
stylesheets) makes this impractical for the case in the original post.
Therefore, for that particular case, I'd personally let it slide.
There's no good way to do conditionals around scripts, and core
doesn't appear to be looking to add a way to do it at present. And
what with IE7 going into EOL, and what with IE10 ignoring these style
of conditionals anyway, it's a problem that will eventually go away.

Always enqueue in a callback, if possible. It's just good practice.
Javascripts are sensitive to load order, generally speaking, and the
enqueue system allows that to work properly.

Here's something I learned today when investigating this: Did you know
style enqueuing supports CSS media queries? I didn't.

wp_enqueue_style( 'themename-phone-style',
get_template_directory_uri().'/css/phone.css', array(), false, 'only
screen and (max-device-width: 480px)' );

Works great. :D

-Otto


More information about the theme-reviewers mailing list