Skip to content

Instantly share code, notes, and snippets.

@ingozoell
Created November 13, 2016 16:19
Show Gist options
  • Save ingozoell/bb66c467973f6722842f5bd5ba993a11 to your computer and use it in GitHub Desktop.
Save ingozoell/bb66c467973f6722842f5bd5ba993a11 to your computer and use it in GitHub Desktop.
WordPress - Enqueue scripts conditional IE
// WP 4.2+
wp_enqueue_script( 'html5shiv', '//cdn.jsdelivr.net/html5shiv/3.7.2/html5shiv.js' );
wp_script_add_data( 'html5shiv', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'respond', get_template_directory_uri() . '/js/respond.min.js' );
wp_script_add_data( 'respond', 'conditional', 'lt IE 9' );
// WP 4.1
wp_enqueue_script( 'html5shiv', '//cdn.jsdelivr.net/html5shiv/3.7.2/html5shiv.js', array(), '3.7.2', false );
add_filter( 'script_loader_tag', function( $tag, $handle ) {
if ( $handle === 'html5shiv' ) {
$tag = "<!--[if lt IE 9]>$tag<![endif]-->";
}
return $tag;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment