Using WordPress' wp_enqueue_style() With Conditionals

Since I always seem to lose track of the ticket where Ozz explains how to do this, putting it here for posterity. When using wp_enqueue_style you may need to use CSS conditional comments to work around IE bugs. Here's the code to add a style for IE 7 named ie7.css located in the root of the theme:

wp_enqueue_style(
   'ie7-style',
   get_template_directory_uri() . '/ie7.css'
);
global $wp_styles;
$wp_styles->add_data( 'ie7-style', 'conditional', 'lte IE 7′ );
 

3 Comments

  1. Posted April 13, 2010 at 5:18 am | Permalink

    Wow! I had no idea that was possible. I decided a long time ago that it was impossible and had many "experts" confirm as such. I guess we were all wrong then!

    Thanks very much for the code snippet :D

  2. Mark
    Posted July 16, 2010 at 12:32 pm | Permalink

    Wow this is great. So simple.

    Is it possible to do this with external javascript files as well?

  3. Posted July 29, 2010 at 9:46 am | Permalink

    @Mark, yes it is.

One Trackback

  1. [...] [...]

Post a Comment

Your email is never shared. Required fields are marked *

*
*