How do I enqueue a js file in functions.php for a if lt IE 9 statement?

I’m coding a theme that uses the Twitter Bootstrap 3 files and in the header I want to include:

<!--[if lt IE 9]>
 <script src="<?php echo get_stylesheet_directory_uri(); ?>/js/html5shiv.js"></script>
  <script src="<?php echo get_stylesheet_directory_uri(); ?>/js/respond.min.js"></script>
<![endif]-->

I’ve been told by a theme reviewer that I can’t put it in the header file (only one js is allowed).

Read More

Required: Theme can include only one JS within header.php, please enqueue the additional > respond.min.js using the hook wp_enqueue_scripts in functions.php

as it is I have to enqueue it, but I don’t know how to do this in a way that put’s it in the “if it IE 9” statement.

Please could someone help me?
Thanks

Related posts

Leave a Reply

1 comment

  1. You can do it in two ways….

    Solution One:

    <?php
    add_action( 'wp_head', 'myscript' );
    function myscript(){
       echo '<!--[if lt IE 9]><script src="your_js_file_path"></script><![endif]-->';
    };
    ?>
    

    Solution Two:

    <?php 
    global $wp_scripts;
    wp_register_script( 'jsFileIdentifier', 'YourJsFilePath',  array(),  '3.6.2' );
    $wp_scripts->add_data( 'jsFileIdentifier', 'conditional', 'lt IE 9' );
    ?>