Skip to content

Instantly share code, notes, and snippets.

@sirchrispy
Forked from wpscholar/functions.php
Last active December 30, 2015 09:29
Show Gist options
  • Save sirchrispy/7809799 to your computer and use it in GitHub Desktop.
Save sirchrispy/7809799 to your computer and use it in GitHub Desktop.
WP: Conditional IE stylesheets from child theme
<?php
add_action( 'wp_enqueue_scripts', 'child_theme_scripts' );
function child_theme_scripts() {
global $wp_styles;
/**
* Load our IE-only stylesheet for all versions of IE:
* <!--[if IE]> ... <![endif]-->
*/
wp_enqueue_style( 'my-theme-ie', CHILD_URL . '/css-ie/style-ie.css', array(), PARENT_THEME_VERSION );
$wp_styles->add_data( 'my-theme-ie', 'conditional', 'IE' );
/**
* Load our IE version-specific stylesheet:
* <!--[if IE 7]> ... <![endif]-->
*/
wp_enqueue_style( 'my-theme-ie7', CHILD_URL . '/css-ie/style-ie7.css', array(), PARENT_THEME_VERSION );
$wp_styles->add_data( 'my-theme-ie7', 'conditional', 'IE 7' );
/**
* Load our IE specific stylesheet for a range of older versions:
* <!--[if lte IE 8]> ... <![endif]-->
* NOTE: You can use the 'less than' or the 'less than or equal to' syntax here interchangeably.
*/
wp_enqueue_style( 'my-theme-lte8', CHILD_URL . '/css-ie/style-lte8.css', array(), PARENT_THEME_VERSION );
$wp_styles->add_data( 'my-theme-lte8', 'conditional', 'lte IE 8' );
/**
* Load our IE specific stylesheet for a range of newer versions:
* <!--[if gte IE 9]> ... <![endif]-->
* NOTE: You can use the 'greater than' or the 'greater than or equal to' syntax here interchangeably.
*/
wp_enqueue_style( 'my-theme-gte8', CHILD_URL . '/css-ie/style-lte8.css', array(), PARENT_THEME_VERSION );
$wp_styles->add_data( 'my-theme-gte8', 'conditional', 'gte IE 9' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment