Last active
August 25, 2018 11:44
-
-
Save GaryJones/1698719 to your computer and use it in GitHub Desktop.
Conditionally add IE style sheets in WP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_print_styles', 'child_add_ie7_style_sheet', 200 ); | |
/** | |
* Enqueue an IE-specific style sheet (for all browsers). | |
* | |
* @author Gary Jones | |
* @link https://garyjones.io/ie-conditional-style-sheets-wordpress | |
*/ | |
function child_add_ie7_style_sheet() { | |
wp_enqueue_style( 'ie7', get_stylesheet_directory_uri() . '/style-ie7.css', [], '1.0' ); | |
} | |
add_filter( 'style_loader_tag', 'child_make_ie7_style_sheet_conditional', 10, 2 ); | |
/** | |
* Add conditional comments around IE7-specific style sheet link. | |
* | |
* @author Gary Jones & Michael Fields (@_mfields) | |
* @link https://garyjones.io/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
Change:
To:
Please see: http://core.trac.wordpress.org/ticket/19510 :)