Skip to content

Instantly share code, notes, and snippets.

@grappler
Last active January 21, 2017 08:06
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save grappler/05568f05633484499acc to your computer and use it in GitHub Desktop.
Save grappler/05568f05633484499acc to your computer and use it in GitHub Desktop.
// add ie conditional html5 shim to header
<?php
// add ie conditional html5 shim to header
function _s_add_ie_html5_shim () {
echo '<!--[if lt IE 9]>';
echo '<script src="' . get_template_directory_uri() . '/js/html5.js"></script>';
echo '<![endif]-->';
}
add_action('wp_head', '_s_add_ie_html5_shim');
<?php
/**
* Enqueue scripts and styles.
*/
function _s_scripts() {
wp_enqueue_script( '_s-html5shiv', get_template_directory_uri() . '/js/html5shiv.js', array(), '3.7.2', false );
}
add_action( 'wp_enqueue_scripts', '_s_scripts' );
/**
* Load only in IE as of WP 4.1
*/
function _s_html5shiv( $tag, $handle, $src ) {
if ( '_s-html5shiv' === $handle ) {
$tag = "<!--[if lt IE 9]>\n" . $tag . "<![endif]-->\n";
}
return $tag;
}
add_filter( 'script_loader_tag', '_s_html5shiv', 10, 3 );
<?php
/**
* Enqueue scripts and styles.
*/
function _s_scripts() {
wp_enqueue_script( '_s-html5shiv', get_template_directory_uri() . '/js/html5shiv.js', array(), '3.7.2', false );
wp_script_add_data( '_s-html5shiv', 'conditional', 'lt IE 9' );
}
add_action( 'wp_enqueue_scripts', '_s_scripts' );
@grappler
Copy link
Author

@bryanwillis Thanks I did not know about the function wp_script_add_data()

I am not sure why a caching plugin would break this as the code is just generating HTML code which will be present on every page.

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