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:

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

6 thoughts on “Using WordPress’ wp_enqueue_style() With Conditionals

  1. 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 πŸ˜€

  2. Thank you for this – just a note for child themes, use get_stylesheet_directory_uri() instead of get_template_directory_uri(), assuming you save your IE stylesheet in your child theme folder. Which you should. πŸ™‚

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s