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 trialilithya
19,818 Points'wp_register_script' for 'HTML5Shiv' is not working for IE
The following function wasn't working for me as of WordPress Version 4.3.1.
function theme_js() {
global $wp_scripts;
wp_register_script( 'html5_shiv', 'http://html5shiv.googlecode.com/svn/trunk/html5.js', '', '', false);
$wp_scripts->add_data('html5_shiv', 'conditional', 'lt IE 9');
}
add_action( 'wp_enqueue_scripts', 'theme_js' );
I had to use 'wp_enqueue' instead of 'wp_register':
wp_enqueue_script( 'html5_shiv', 'http://html5shiv.googlecode.com/svn/trunk/html5.js', '', '', false);
Nevertheless, now the script is loading in all browsers with the IE conditional comment.
I was wondering if there's still a way that the script will load only in the conditional IE browsers stated (E.g. IE8 and below). So that for example Chrome and Firefox has no need to show this up.
1 Answer
Stanley Thijssen
22,831 PointsHi,
How did you test this? If u checked whether the code was added to your html by using any browser which is not IE and not lower then IE 9 you cant see it. This is because it's added as a conditional code which only shows up when the browser is IE and lower then version IE 9.
ilithya
19,818 Pointsilithya
19,818 PointsHi Stanley,
Thank you for the quick response.
I was testing IE10 - IE7 on Windows 7 via a Virtual Machine.
I couldn't see it nor in IE10, IE9, IE8 or IE7. Nevertheless, when I added the 'wp_register_script', I could see it everywhere. Not only on browsers lower than IE9.
To my experience, Virtual Machine Windows 7, IE, reflects exactly a site code, as if viewed on a regular Windows Machine.
If you still have any input after my answer, I'll appreciate it!