First, you always need to use the no-conflict wrapper in Wordpress, so your code will look like this:
jQuery(document).ready(function($){ alert('Hello World!'); });
Secondly, it is good practice to place your javascript in external files, and in the Wordpress plugin you would include the following elements:
wp_register_script( 'my_plugin_script', plugins_url('/my_plugin.js', __FILE__), array('jquery')); wp_enqueue_script( 'my_plugin_script' );
This includes your script and sets jQuery as a dependency, so Wordpress will automatically load jQuery if it is not already loaded, so that it loads only once and loads before your script plugins.
And if you only need a script on the admin pages, you can load it conditionally using the Wordpress add_action handlers:
add_action( 'admin_menu', 'my_admin_plugin' ); function my_admin_plugin() { wp_register_script( 'my_plugin_script', plugins_url('/my_plugin.js', __FILE__), array('jquery')); wp_enqueue_script( 'my_plugin_script' );
source share