我使用此函数注册主题使用的各种脚本并将其排队:
function cosmos_enqueue_scripts() {
// Load jquery from Google CDN (protocol relative) with local fallback when not available
if ( false === ( $url = get_transient(\'jquery_url\') ) ) {
// Check if Google CDN is working
$url = ( is_ssl() ? \'https:\' : \'http:\' ) . \'//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js\';
$resp = wp_remote_head($url);
// Load local jquery if Google down
if ( is_wp_error($resp) || 200 != $resp[\'response\'][\'code\'] ) {
$url = get_template_directory_uri() . \'/js/vendor/jquery-1.7.2.min.js\';
}
// Cache the result for 5 minutes to save bandwidth
set_transient(\'jquery_url\', $url, 60*5);
}
// Deregister Wordpress\' jquery and register theme\'s copy in the footer
wp_deregister_script(\'jquery\');
wp_register_script(\'jquery\', $url, array(), null, true);
// Load other theme scripts here
wp_enqueue_script(\'modernizr\', get_template_directory_uri() . \'/js/vendor/modernizr-2.5.3.min.js\', array( ), null, false);
wp_enqueue_script(\'bootstrap\', get_template_directory_uri() . \'/js/vendor/bootstrap.min.js\' , array(\'jquery\'), null, true );
wp_enqueue_script(\'main\' , get_template_directory_uri() . \'/js/main.js\' , array(\'jquery\'), null, true );
}
add_action(\'wp_enqueue_scripts\', \'cosmos_enqueue_scripts\');