I have my wordpress page and aparently it already loads JQuery, but if I don’t load it again (exactly the same version moreover), any Jquery function I use will fail showing $ is not recognized.
example: https://delaytelo.com/recipes/
It’s loaded twice, but removing the one from cloudflare will make the page break…
2
Answers
As per the comments, you will need to do this:
The reason is not that you are trying to use jQuery before it is initialized. The actual reason is that:
jQuery
and NOT as$
. Within a WordPress site, jQuery is never abbreviated to$
, because it might conflict with other javascript libraries that have$
as identifier.Still, you can use
$
inside a document ready callback if you provide it as the argument, since jQuery is programmed to supply its own object as the argument to this document ready function. So this:function($)
will make the jQuery object available inside the function as$
.jQuery(function($){});
should be used…For people wondering what the issue was: The Jquery was being used without a function that checks if Jquery is loaded yet. For example:
jQuery(document).ready(function($) {
})
Read more:
How do I add a simple jQuery script to WordPress?