Just started developing a plugin for WordPress, wanted to use some JQuery in the Plugin Admin interface.
How do I properly include and call JQuery?
For instance, on a normal HTML page I would just include the JQuery library, then call this script:
$(document).ready(function(){
alert('Hello World!');
});
How can I do this in a WordPress Plugin PHP file?
It is not recommended to be using your own jquery version.
So you should use this instead:
Firstly, you always have to use a no-conflict wrapper in Wordpress, so your code would look like :
Secondly, it's good practice to put your javascript in external files, and in a Wordpress plugin you would include those like this :
This includes your script, and sets up jQuery as a dependency, so Wordpress will automatically load jQuery if it's not already loaded, making sure it's only loaded once, and that it's loaded before your plugins script.
And if you only need the script on the admin pages, you can load it conditionally using Wordpress add_action handlers: