Title: enqueue javascript js with conditional comments (for IE)
Last modified: August 19, 2016

---

# enqueue javascript js with conditional comments (for IE)

 *  [Josh S.](https://wordpress.org/support/users/jahshuwaa/)
 * (@jahshuwaa)
 * [16 years ago](https://wordpress.org/support/topic/enqueue-javascript-js-with-conditional-comments-for-ie/)
 * Working in the theme’s functions.php, how can I wp_enqueue_script a javascript
   file with conditional comments (for IE)?
 * On the inclusion of CSS, wp_enqueue_style supports this for CSS with the following,
   for example:
    $wp_styles->add_data( ‘theme-ie6’, ‘conditional’, ‘lt IE 7’ );
 * Results output:
    <!–[if lt IE 7]> <link rel=’stylesheet’ id=’theme-ie6-css’ href
   =’/wp-content/themes/test/style_ie6.css?ver=1.0.0′ type=’text/css’ media=’all’/
   > <![endif]–>
 * I thought the same techniques should work for wp_enqueue_script but I have not
   been successful.
 * DESIRED RESULT on page/post/etc:
    <!–[if lt IE 9]> <script src=”[http://html5shiv.googlecode.com/svn/trunk/html5.js”></script&gt](http://html5shiv.googlecode.com/svn/trunk/html5.js”></script&gt);
   <![endif]–>
 * CODE TO ACHIEVE? (in functions.php of theme):
    global $wp_scripts; wp_register_script(‘
   html5shiv’,’[http://html5shiv.googlecode.com/svn/trunk/html5.js&#8217](http://html5shiv.googlecode.com/svn/trunk/html5.js&#8217);,
   array(),’1.5.1′); wp_enqueue_script(‘html5shiv’); $wp_scripts->add_data( ‘html5shiv’,‘
   conditional’, ‘lt IE 9’ ); // DOES NOT WORK
 * Need some expert help here to properly enqueue the scripts with conditional comments

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Thread Starter [Josh S.](https://wordpress.org/support/users/jahshuwaa/)
 * (@jahshuwaa)
 * [16 years ago](https://wordpress.org/support/topic/enqueue-javascript-js-with-conditional-comments-for-ie/#post-1503579)
 * Still no progress on this. Is there a hook?
 *  Thread Starter [Josh S.](https://wordpress.org/support/users/jahshuwaa/)
 * (@jahshuwaa)
 * [16 years ago](https://wordpress.org/support/topic/enqueue-javascript-js-with-conditional-comments-for-ie/#post-1503613)
 * Would a Mod please move this to the advanced forum?
 *  Moderator [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [16 years ago](https://wordpress.org/support/topic/enqueue-javascript-js-with-conditional-comments-for-ie/#post-1503626)
 * A simple if IE should do it.
 *     ```
       <!--[if IE]>
       <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
       <![endif]-->
       ```
   
 *  [Björn Ali Göransson](https://wordpress.org/support/users/bornemix/)
 * (@bornemix)
 * [15 years, 12 months ago](https://wordpress.org/support/topic/enqueue-javascript-js-with-conditional-comments-for-ie/#post-1503646)
 * Jahshuwaa,
 * This feature is implemented in the styles part of wordpress as of now (even wordpress
   3, latest build, doesn’t have it).
 *  [wmrom](https://wordpress.org/support/users/wmrom/)
 * (@wmrom)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/enqueue-javascript-js-with-conditional-comments-for-ie/#post-1503660)
 * jahshuwaa: There doesn’t seem to be a hook. I think this would be a good enhancement
   request for 3.1
 * I looked on trac and found this:
    [http://core.trac.wordpress.org/ticket/10891](http://core.trac.wordpress.org/ticket/10891)
 * So it’s on the radar.
 *  [Mark Jaquith](https://wordpress.org/support/users/markjaquith/)
 * (@markjaquith)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/enqueue-javascript-js-with-conditional-comments-for-ie/#post-1503669)
 * Also consider that you can use the global `$is_IE` to determine IE, and only 
   enqueue if so. But if you want to not enqueue for IE 9 and higher, you’ll have
   to do some User Agent parsing yourself.
 * Also worth reading, on the subject of HTML5 support detection:
 * [http://diveintohtml5.org/everything.html](http://diveintohtml5.org/everything.html)
 *  Thread Starter [Josh S.](https://wordpress.org/support/users/jahshuwaa/)
 * (@jahshuwaa)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/enqueue-javascript-js-with-conditional-comments-for-ie/#post-1503670)
 * wmrom, good info. Thank you for the trac link.
 * markjaquith, great suggestion and resource. I’ll parse the user agent string 
   in this case to enqueue conditionally.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘enqueue javascript js with conditional comments (for IE)’ is closed to
new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [enqueue](https://wordpress.org/support/topic-tag/enqueue/)
 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 7 replies
 * 5 participants
 * Last reply from: [Josh S.](https://wordpress.org/support/users/jahshuwaa/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/enqueue-javascript-js-with-conditional-comments-for-ie/#post-1503670)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
