我删除jquery.min.js wordpress时的问题

发布于 2025-02-12 06:15:27 字数 437 浏览 3 评论 0原文

我想删除jquery.min.js。因为我不需要。为此,有必要不使用“ wp_deregister_script”。

我还手动添加了主题的JS文件。

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

但是,当我手动添加主题的JS文件不起作用。 当我与Chrome检查时,我看到了以下错误。

未介绍的参考:未定义jQuery https://sitet/wp-content/themes/mytema/js/scripts.js:1

不需要参考。现在只有一个JS文件。如何解决此问题?谢谢。

I want to remove jquery.min.js. because I don't need it. For this, it is necessary not to use "wp_deregister_script".

I also added the theme's js file manually.

<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.
When I checked with Chrome, I saw the following error.

Uncaught ReferenceError: jQuery is not defined
https://sitet/wp-content/themes/mytema/js/scripts.js:1

There is no need for a reference. There is only one js file now. How can I fix this problem? thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

计㈡愣 2025-02-19 06:15:35

这很简单。您没有任何jQuery文件,但是代码中想要使用jQuery对象。您要么必须删除包含jQuery的代码,要么必须使用jquery.min.js。

并要手动加入js文件,请关注此 https://developer.wordpress.org/themes/basics/including-css-javascript/

谢谢

This is pretty simple. You have no any jquery file but in code wanted to use the jQuery object. Either you have to remove the code where contain the jQuery or you have to use the jquery.min.js.

And to manually enqueue the js file please follow this https://developer.wordpress.org/themes/basics/including-css-javascript/

Thank you

無處可尋 2025-02-19 06:15:34

也许在JS脚本上方包含使用jQuery对象的代码。我建议您检查该部分并使用“ WP_enqueue_script Hook” F插入脚本。

https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/#:~: text = wp_enqueue_scripts;

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');
}

Perhaps above js script contains a code that uses the jquery object. I recommend that you check that part and use "wp_enqueue_script hook"f to insert the script.

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');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文