@Milo已经指出了这一点,只需将您的脚本与jQuery列为依赖项即可。当WordPress加载脚本时,它将看到依赖项并自动为您加载jQuery。例如:
function enqueue_my_scripts(){
if( ! is_admin() )
wp_enqueue_script( \'stacked-script\', get_bloginfo(\'stylesheet_directory\') . \'/scripts/stacked.js\', array(\'jquery\'), \'1.0.1\' );
}
add_action( \'wp_enqueue_scripts\', \'enqueue_my_scripts\' );
将在站点标题中显示以下内容:
<script type=\'text/javascript\' src=\'http://site-url.com/wp-includes/js/jquery/jquery.js?ver=1.6.1\'></script>
<script type=\'text/javascript\' src=\'http://site-url.com/wp-content/themes/stacked-theme/scripts/stacked.js?ver=1.0.1\'></script>
jQuery将首先加载,然后加载脚本。