The WP.SE community has always advised the use of wp_register_script
and wp_enqueue_script
for adding scripts in a theme/template (and likewise, wp_register_style
and wp_enqueue_style
for stylesheets).
This is how I register and enqueue my scripts...
First, I add something like this in functions.php
add_action('init','wpse54189_register_script');
function wpse54189_register_script(){
//Register scripts
wp_enqueue_script( 'jquery' );
wp_register_script( 'aahan_bootstrap_transition', get_template_directory_uri().'/js/bootstrap-transition.js');
wp_register_script( 'aahan_bootstrap_carousel', get_template_directory_uri().'/js/bootstrap-carousel.js', array('aahan_bootstrap_transition'));
wp_register_script( 'wpse54189_ajax_comment', get_template_directory_uri().'/js/no-reload-comments.js');
}
then call it in a template file (say, header.php) like this
<?php wp_enqueue_script( 'aahan_bootstrap_carousel' ); ?>
<?php wp_enqueue_script( 'wpse54189_ajax_comment' ); ?>
Now, coming to the point, how do I register and enqueue "conditional JavaScript files" that are there to be recognized by specific browsers? For example:
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<![endif]-->
How do I register and enqueue this properly?
PS: I use the Reddle theme, developed by the theme wranglers at Automattic. And the theme's header.php directly uses the just aforementioned code -- i.e. it's not enqueued. So, does that mean, it's the only way to do it?