第一部分
好,那么在你的主题/插件中你有:
wp_enqueue_script( \'jquery\' );
wp_enqueue_script( \'scripts\', get_template_directory_uri() . \'/js/scripts.min.js\', array( \'jquery\' ) );
第一行,排队
jquery 没有必要-你把
jquery 作为第二行中的依赖项,因此无论如何都会包含它。
这些行通知WP您要将给定文件排队为scripts 它需要用handle注册脚本jquery - 因此,它将在脚本之前自动排队。
第二部分
add_filter( \'wp_default_scripts\', \'remove_jquery_migrate\' );
function remove_jquery_migrate( &$scripts){
if(!is_admin()){
$scripts->remove( \'jquery\');
$scripts->add( \'jquery\', false, array( \'jquery-core\' ), \'1.2.1\' );
}
}
正如你在
Plugin API/Action Reference, 这个钩子叫做相当早。。。Waaaaay之前
wp_enqueue_scripts.
And what it really does?
它删除带有句柄的脚本
jquery 从默认脚本,然后将其添加到不同的依赖项中(仅限
jquery-core).
add 方法来自WP_Dependencies 类别:
WP_Dependencies::add( string $handle, string $src, array $deps = array(), string|bool|null $ver = false, mixed $args = null )
为什么是这个版本版本
1.2.1 只是一个缓存助推器。WordPress不分析它。它用作
?ver param,因此浏览器必须在版本更改时重新加载该文件。。。您可以在其中放入任何内容-当然,使用给定脚本的真实版本是一个好主意;)