Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danemorgan/6445801 to your computer and use it in GitHub Desktop.
Save danemorgan/6445801 to your computer and use it in GitHub Desktop.
Wrap stylesheet in ie conditional tags for wp_head
<?php
add_action( 'wp_enqueue_scripts', 'child_add_ie7_style_sheet', 200 );
/**
* Enqueue a IE-specific style sheet (for all browsers).
*
* @author Gary Jones
* @link http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/
*/
function child_add_ie7_style_sheet() {
wp_enqueue_style( 'ie7', get_stylesheet_directory_uri() . '/style-ie7.css', array(), '1.0' );
}
add_filter( 'style_loader_tag', 'child_make_ie7_style_sheet_conditional', 10, 2 );
/**
* Add conditional comments around IE-specific style sheet link.
*
* @author Gary Jones & Michael Fields (@_mfields)
* @link http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/
*
* @param string $tag Existing style sheet tag.
* @param string $handle Name of the enqueued style sheet.
*
* @return string Amended markup
*/
function child_make_ie7_style_sheet_conditional( $tag, $handle ) {
if ( 'ie7' == $handle )
$tag = '<!--[if lte IE 7]>' . "\n" . $tag . '<![endif]-->' . "\n";
return $tag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment