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.
CodePudding user response:
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.
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');
}
CodePudding user response:
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