Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roborourke/2567027 to your computer and use it in GitHub Desktop.
Save roborourke/2567027 to your computer and use it in GitHub Desktop.
Enables !IE in wordpress's conditional comments for styles mechanism
<?php
add_filter( 'style_loader_tag', 'style_loader_tag_ccs', 10, 2 );
/**
* Add support for non IE conditional comments
*
* Trac ticket: http://core.trac.wordpress.org/ticket/16118
*
* Usage:
* After registering or enqueuing a script you need to append the CC to the style
* handle via the $wp_styles class:
*
* $wp_styles->add_data( 'my-handle', 'adv_conditional', '!IE' );
*
* @param string $tag The <link> tag to the CSS file
* @param string $handle The handle the style was registerd with
*
* @return string Returns the link tag for output
*/
function style_loader_tag_ccs( $tag, $handle ) {
global $wp_styles;
$obj = $wp_styles->registered[ $handle ];
if ( isset( $obj->extra[ 'adv_conditional' ] ) && $obj->extra[ 'adv_conditional' ] ) {
$cc = "<!--[if {$obj->extra['adv_conditional']}]>";
$end_cc = '';
if ( strstr( $obj->extra['adv_conditional'], '!IE' ) ) {
$cc .= '<!-->';
$end_cc = '<!--';
}
$end_cc .= "<![endif]-->\n";
$tag = $cc . "\n" . $tag . $end_cc;
}
return $tag;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment