olivierGrech olivierGrech - 4 months ago 5x
jQuery Question

Wordpress - registering a script depending on JQuery

I register and enqueue my script like this:

wp_register_script('api_script', plugins_url('api.js', __FILE__), array('jquery'));

My api.js file consist only of a call to the
function :


However, I'm getting the following error:
TypeError: $ is undefined
Help please!


When writing javascript with jQuery for Wordpress you want to write "safe" jQuery functions by not using the dollar sign. You can use:


Or you can pass a dollar sign as a parameter like this:

(function($) {

And it then runs an anonymous function with a parameter passing the jQuery object.