Skip to content

Instantly share code, notes, and snippets.

@danemorgan
Forked from GaryJones/functions.php
Last active December 22, 2015 08:29
Show Gist options
  • Save danemorgan/6445526 to your computer and use it in GitHub Desktop.
Save danemorgan/6445526 to your computer and use it in GitHub Desktop.
.Untested. Should wrap javascript in ie conditional tags. Will update after testing.
<?php
add_action( 'wp_enqueue_scripts', 'child_add_ie_script', 200 );
/**
* Enqueue a IE-specific style sheet (for all browsers).
* @author Gary Jones
* @link http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/
*/
function child_add_ie_script() {
wp_enqueue_script( 'ie-only', get_stylesheet_directory_uri() . '/js/style-ie7.js', array(), '1.0' );
}
add_filter( 'style_loader_tag', 'child_make_ie_script_conditional', 10, 2 );
/**
* Add conditional comments around IE-specific script link.
*
* @author Gary Jones & Michael Fields (@_mfields)
* @link http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/
*
* @param string $tag Existing script tag.
* @param string $handle Name of the enqueued script.
*
* @return string Amended markup
*/
function child_make_ie_script_conditional( $tag, $handle ) {
if ( 'ie-only' == $handle )
$tag = '<!--[if lte IE 7]>' . "\n" . $tag . '<![endif]-->' . "\n";
return $tag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment