Do we have to register JQuery if we want to use it in wp_enqueue_script()?

Or is it registered by default?
I am enqueuing a script with wp_enqueue_script()

wp_enqueue_script('validation', 'http://domain.com/wordpress/wp-content/themes/theme/js/validation.js', array('jquery'));

But I get this error in the console:

Read More

Uncaught TypeError: Property '$' of object [object Object] is not a function

Also do I need to put the absolute path to link my js, or can I use a relative path? Relative to what?

Related posts

1 comment

  1. You don’t need to register it but in your own js file, replace the first $ to jQuery.

    jQuery is loaded in No Conflict Mode

    jQuery(document).ready(function($) {
        // Your code here. Use $ as normal.
    });
    

    And if you use anonymous functions, do it like this

    (function($) {
       // Your code here. Use $ as normal.
    })(jQuery);
    

    Also, you need to use relative paths.

Comments are closed.