Last active
August 16, 2017 19:46
-
-
Save nr1q/d39193c91ca2513a32bdad19aa453da6 to your computer and use it in GitHub Desktop.
Enqueueing IE conditional stylesheets in WordPress the right way
This file contains 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_enqueue_scripts', 'enqueue_my_styles_and_scripts' ); | |
/** | |
* Enqueue styles and scripts conditionally. | |
* | |
* Load stylesheets and scripts specifically for IE. IE10 and above does | |
* not support conditional comments in standards mode. | |
* | |
* @link https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx | |
*/ | |
function enqueue_my_styles_and_scripts() { | |
// Internet Explorer specific stylesheet. | |
wp_enqueue_style( 'themename-ie', get_stylesheet_directory_uri() . '/css/ie.css', array( 'twentyfifteen-style' ), '20141010' ); | |
wp_style_add_data( 'themename-ie', 'conditional', 'lte IE 9' ); | |
// Internet Explorer 7 specific stylesheet. | |
wp_enqueue_style( 'themename-ie7', get_stylesheet_directory_uri() . '/css/ie7.css', array( 'twentyfifteen-style' ), '20141010' ); | |
wp_style_add_data( 'themename-ie7', 'conditional', 'lt IE 8' ); | |
// Internet Explorer HTML5 support | |
wp_enqueue_script( 'html5shiv',get_template_directory_uri().'/js/html5shiv.js', array(), '3.7.3', false); | |
wp_script_add_data( 'html5shiv', 'conditional', 'lt IE 9' ); | |
// Internet Explorer 8 media query support | |
wp_enqueue_script( 'respond', get_template_directory_uri().'/js/respond.js', array(), '1.4.2', false); | |
wp_script_add_data( 'respond', 'conditional', 'lt IE 9' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is based on this comment from another gist.