Skip to content

Instantly share code, notes, and snippets.

@jeremyfelt
Created March 2, 2012 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeremyfelt/1960725 to your computer and use it in GitHub Desktop.
Save jeremyfelt/1960725 to your computer and use it in GitHub Desktop.
Conditional WordPress stylesheets
<?php
/* Register our IE specific stylesheets. */
wp_register_style( 'prefix-ie7-only', get_template_directory_uri() . '/css/ie7.css' );
wp_register_style( 'prefix-ie8-only', get_template_directory_uri() . '/css/ie8.css' );
wp_register_style( 'prefix-ie9-only', get_template_directory_uri() . '/css/ie.css' );
/* Use the global wp_styles object to add our conditional statements due to the lack
* of conditional support in wp_register_style
*/
$wp_styles->add_data( 'prefix-ie9-only', 'conditional', 'IE 9' );
$wp_styles->add_data( 'prefix-ie8-only', 'conditional', 'IE 8' );
$wp_styles->add_data( 'prefix-ie7-only', 'conditional', 'lt IE 8' );
/* Enqueue the IE specific stylesheets, now with conditional statements attached via global */
wp_enqueue_style( 'prefix-ie7-only' );
wp_enqueue_style( 'prefix-ie8-only' );
wp_enqueue_style( 'prefix-ie9-only' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment