if(! function_exists('register_jquery_script')){
function register_jquery_script(){
/* Get jquery handle - WP 3.6 or newer changed the jQuery handle (once we're on 3.6+ we can remove this logic) */
$jquery_handle = (version_compare($wp_version, '3.6-alpha1', '>=')) ? 'jquery-core' : 'jquery';
/* Get the WP built-in version */
$wp_jquery_ver = $GLOBALS['wp_scripts']->registered[$jquery_handle]->ver;
/* Just in case it doesn't work, add a fallback version */
$jquery_ver = ($wp_jquery_ver == '') ? '1.8.3' : $wp_jquery_ver;
/* the URL to check CDN accessibility */
$url = 'http://ajax.googleapis.com/ajax/libs/jquery/' . $jquery_ver . '/jquery.min.js';
/* test CDN accessibility */
$test_url = wp_remote_fopen($url);
/* deregisters the default WordPress jQuery */
wp_enqueue_script('jquery');
wp_deregister_script('jquery');
/* if CDN available - load it */
if($test_url !== false) {
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/'. $jquery_ver .'/jquery.min.js', false , false , true);
}
/* if CDN unavailable - load local jquery copy */
else{
wp_register_script('jquery', get_template_directory_uri() . '/js/jquery.min.js', __FILE__, false, false, true);
}
wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts','register_jquery_script');
}
,你必须确保你加载本地的jQuery到template_directory/JS与名称/jquery.min.js
我在默认情况下,将加载wp_footer()中的所有脚本用于页面加载性能。 如果您在加载wp_header()的JS脚本,你会改变对行内最后真正到假:
wp_register_script('jquery' , $src , false , false , false);
享受吧!
http://wordpress.org/plugins/wp-jquery-plus/。似乎这就是你需要的。 – elclanrs