Conditional Loading of Javascript-Files using WordPress (if IE)

Since version 4.2 it has become even more easy to load JavaScript files conditionally. Find out how this works in this blog post:

In your functions.php and/or in your plugin file you can use the follwoing function: wp_script_add_data():

add_action( 'wp_enqueue_scripts', 'ab_scripts' );

 * Enqueue scripts and styles.
function ab_scripts() {
	wp_enqueue_script( 'html5shiv', '//', array(), '3.7.2', false );
	wp_script_add_data( 'html5shiv', 'conditional', 'lt IE 9' );

Check your sourcecode on the frontend and you will find something like this:

<!--[if lt IE 9]>
<script type='text/javascript' src='//'></script>

That’s it.