Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Theme Development Working with CSS and JS in WordPress Themes How to Link to JS from functions.php File

SANDRA SOUTO
SANDRA SOUTO
362 Points

How to enqueue conditional scripts for IE?

...

Craig Garrity
Craig Garrity
23,692 Points

Try adding your own named conditional sheets with your relevant paths after the get_template_directory_uri() into your theme functions.php file. In this example respond.min.js and html5shiv are conditionally being loaded in the head.

wp_register_style( 'ie_html5shiv', get_template_directory_uri() . '/js/html5shiv.js' );
    wp_enqueue_style( 'ie_html5shiv');
    wp_style_add_data( 'ie_html5shiv', 'conditional', 'lt IE 9' );

    wp_register_style( 'ie_respond', get_template_directory_uri() . '/js/respond.min.js' );
    wp_enqueue_style( 'ie_respond');
    wp_style_add_data( 'ie_respond', 'conditional', 'lt IE 9' );

2 Answers

Yojance Rabelo
Yojance Rabelo
1,156 Points

Hi There,

Please take a look at this page showing globals you can use to detech all kinds of things, including IE. https://codex.wordpress.org/Global_Variables

In your case, you would do something like:

<?php 
global $is_IE;
if( $is_IE ) {
    // Enqueue your IE scripts
}