function uw_load_scripts() {
// De-register the built in jQuery
wp_deregister_script('jquery');
// Register the CDN version
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js', array(),'','1.1', true);
// Load it in your theme
wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'uw_load_scripts' );
我在 mytheme/function.php 中有这个很好的函数。他们说这应该将 js 移动到页脚,但在我的情况下却没有。知道为什么或/以及如何将其移至页脚吗?
最佳答案
工作原理
在您的代码中,wp_register_script()
的 $in_footer
参数设置为 true
。
您可以通过在调用 wp_enqueue_script()
或 wp_register_script 时将
$in_footer
参数设置为 true
在页脚中排队()
<强> Reference>>
为什么你不能
您指向 jquery 的链接似乎无效。使用正确的链接。 您可以使用这个来代替;
http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js
并且
相应地更改版本或设置 false
,
版本在哪里,
指定脚本版本号的字符串(如果有的话) 作为查询字符串连接到路径的末尾。如果没有版本 指定或设置为 false,则 WordPress 自动添加版本号 等于您当前运行的 WordPress 版本。如果设置为 null 则不 版本已添加。该参数用于保证版本正确 无论缓存如何,都会发送到客户端,因此如果
关于javascript - WordPress:jquery.js 不会移动到页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20718711/