在wordpress中,使用钩子wp_enqueue_script覆盖jQuery版本,但它不起作用.而且我需要两个jquery.
我想为网站定制添加新的jquery版本.
但是当我添加新版本的jQuery时,旧版本的jQuery在功能上不起作用
function.PHP:
function themeslug_enqueue_script(){
wp_enqueue_script('child_theme_script_handle', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js',
array( 'jquery' ), '3.2.1', true );
wp_enqueue_script( 'my-great-script', get_stylesheet_directory_uri() . '/core/assets/js/multi-vendors.js',
array( 'jquery' ), '1.0', true );
}
add_action('wp_enqueue_scripts', 'themeslug_enqueue_script');
jQuery.js:
$(document).ready(function(){
alert('Hello');
});
有些在功能上不起作用.例如,滑块.
解决方法:
您需要首先注销旧版本脚本并加入新版本.
请使用此代码更改jquery版本.
<?PHP function modify_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', false, '1.7.2');
wp_enqueue_script('jquery');
}
}
add_action('init', 'modify_jquery'); ?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。