Skip to content

Instantly share code, notes, and snippets.

@nr1q
Last active August 16, 2017 19:46
Show Gist options
  • Save nr1q/d39193c91ca2513a32bdad19aa453da6 to your computer and use it in GitHub Desktop.
Save nr1q/d39193c91ca2513a32bdad19aa453da6 to your computer and use it in GitHub Desktop.
Enqueueing IE conditional stylesheets in WordPress the right way
<?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' );
}
@nr1q
Copy link
Author

nr1q commented Aug 16, 2017

This gist is based on this comment from another gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment