0

How can I include jQuery file into my plugin so I can use it on plugin page?

2

1 Answer 1

2

JQuery is a part of Wordpress core, so it is automatically there for you to use (i.e. you do not need to register it). However, you still need to enqueue it.

This can be done as follows:

function my_script() {
  wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'my_script');

This loads jQuery from Wordpress core, the jQuery files can be found at /wp-includes/js/jquery/jquery.js if you are interested.

Alternatively you can include jQuery as a dependency when you enqueue your own JavaScript file as follows (notice the 3rd argument):

wp_enqueue_script( 'my_script_handle', plugins_url(('js/some_script.js, __FILE__), array('jquery'), '1.0', true);

where some_script.js is your own JavaScript file which is assumed to be in the 'js' directory of your plugin in the example.

You can find out more about the wp_enqueue_script parameters on the Wordpress Developer Help.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.