简体   繁体   中英

Problem when I removed jquery.min.js wordpress

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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