简体   繁体   English

当我删除 jquery.min.js wordpress 时出现问题

[英]Problem when I removed jquery.min.js wordpress

I want to remove jquery.min.js.我想删除 jquery.min.js。 because I don't need it.因为我不需要它。 For this, it is necessary not to use "wp_deregister_script".为此,必须不要使用“wp_deregister_script”。

I also added the theme's js file manually.我还手动添加了主题的 js 文件。

<script type='text/javascript' src='http://site/wp-content/themes/mytema/js/scripts.js'></script>

but the js file of the theme does not work when I add it manually.但是当我手动添加时,主题的js文件不起作用。 When I checked with Chrome, I saw the following error.当我检查 Chrome 时,我看到了以下错误。

Uncaught ReferenceError: jQuery is not defined https://sitet/wp-content/themes/mytema/js/scripts.js:1未捕获的 ReferenceError:未定义 jQuery https://sitet/wp-content/themes/mytema/js/scripts.js:1

There is no need for a reference.没有必要参考。 There is only one js file now.现在只有一个js文件。 How can I fix this problem?我该如何解决这个问题? thanks.谢谢。

Perhaps above js script contains a code that uses the jquery object.也许上面的 js 脚本包含使用 jquery 对象的代码。 I recommend that you check that part and use "wp_enqueue_script hook"f to insert the script.我建议您检查该部分并使用“wp_enqueue_script hook”f 插入脚本。

https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/#:~:text=wp_enqueue_scripts%20is%20the%20proper%20hook,enqueuing%20both%20scripts%20and%20styles . https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/#:~:text=wp_enqueue_scripts%20is%20the%20proper%20hook,enqueuing%20both%20scripts%20and%20styles

add_action('wp_enqueue_scripts', 'my_register_script_method');

function my_register_script_method () {
    wp_register_script( 'jqueryexample', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jqueryexample.min.js');
}
function my_register_script_method () {
    wp_deregister_script('jquery');
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jqueryexample.min.js');
}

This is pretty simple.这很简单。 You have no any jquery file but in code wanted to use the jQuery object.您没有任何 jquery 文件,但在代码中想要使用 jQuery 对象。 Either you have to remove the code where contain the jQuery or you have to use the jquery.min.js.要么你必须删除包含 jQuery 的代码,要么你必须使用 jquery.min.js。

And to manually enqueue the js file please follow this https://developer.wordpress.org/themes/basics/including-css-javascript/要手动将 js 文件排入队列,请遵循此https://developer.wordpress.org/themes/basics/including-css-javascript/

Thank you谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM