该WP.SE社区一直建议使用wp_register_script
,并wp_enqueue_script
在主题/模板添加脚本(同样地,wp_register_style
并wp_enqueue_style
为样式表)。
这就是我注册和排队脚本的方式...
首先,我在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');
}
然后像这样在模板文件(例如header.php)中调用它
<?php wp_enqueue_script( 'aahan_bootstrap_carousel' ); ?>
<?php wp_enqueue_script( 'wpse54189_ajax_comment' ); ?>
现在,至此,我该如何注册和入列特定浏览器可以识别的“条件JavaScript文件”?例如:
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<![endif]-->
如何正确注册和入队?
PS:我使用Reddle主题,该主题由Automattic的主题牧马人开发。主题的header.php直接使用前面提到的代码-即未排队。那么,这是否意味着这是唯一的方法?