I need to add jQuery library to WordPress page. The page is rendered by a plugin shortcode.

I've used the below methods but I don't see it working for my jQuery script.

I tried to add these below script in main plugin file where the plugin name and version go.


function my_init() {
    if (!is_admin()) {
add_action('init', 'my_init');


function my_init() {
    if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', false, '1.4.2'); 
add_action('init', 'my_init');

I actually need to add below library to my WordPress front end page?


but if i use it directly like below then it works.

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

Second, How can see it loaded in my browser loaded along with other code?

  • You can see if your browser has loaded the script in the network panel of your development tools. Does your theme include a call to wp_head()
    – veganista
    Apr 29, 2015 at 13:21
  • It is highly recommended to use the jQuery version that comes with WordPress core. Apr 29, 2015 at 13:55
  • Hook your action onto wp_enqueue_scripts, not init. Your first example should work fine then, assuming, as @veganista pointed out, that your theme calls wp_head() Apr 29, 2015 at 20:03

1 Answer 1


I think wordpress only loads jQuery when you specify it is a dependency for another script that is loading on that page:

wp_enqueue_script( 'script-name', '/path/script.js', array('jQuery');

If there is no other script then try loading it like a normal script with full path to the file:

wp_enqueue_script( 'myJquery', '//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');

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.