[英]Problem when I removed jquery.min.js wordpress
我想刪除 jquery.min.js。 因為我不需要它。 為此,必須不要使用“wp_deregister_script”。
我還手動添加了主題的 js 文件。
<script type='text/javascript' src='http://site/wp-content/themes/mytema/js/scripts.js'></script>
但是當我手動添加時,主題的js文件不起作用。 當我檢查 Chrome 時,我看到了以下錯誤。
未捕獲的 ReferenceError:未定義 jQuery https://sitet/wp-content/themes/mytema/js/scripts.js:1
沒有必要參考。 現在只有一個js文件。 我該如何解決這個問題? 謝謝。
也許上面的 js 腳本包含使用 jquery 對象的代碼。 我建議您檢查該部分並使用“wp_enqueue_script hook”f 插入腳本。
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');
}
這很簡單。 您沒有任何 jquery 文件,但在代碼中想要使用 jQuery 對象。 要么你必須刪除包含 jQuery 的代碼,要么你必須使用 jquery.min.js。
要手動將 js 文件排入隊列,請遵循此https://developer.wordpress.org/themes/basics/including-css-javascript/
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.