1

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).

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

0

1 Answer 1

4

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' );
?>
3
  • Thanks for your help, If I use the first version how do I include the dynamic path to the js? ( <?php echo get_stylesheet_directory_uri(); ?>/js/html5shiv.js"> )
    – Chris
    Commented Mar 15, 2014 at 17:18
  • You can use the dynamic path just like an regular way like this one....... <?php echo get_template_directory_uri() . '/assets/js/wpm_header_script.js'; ?>
    – Sabbir H
    Commented Mar 16, 2014 at 16:10
  • OK thanks. I found a different way to do this but thankyou for your help.
    – Chris
    Commented Mar 17, 2014 at 17:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.