skip to Main Content

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.

2

Answers


  1. 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');
    }
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search