1

Just about to launch a WordPress site but have noticed that it's currently loading in two jquery files, one in wp-includes and one from my header.php, is there a way to make wordpress load the wp-include one on the front end? Done quite a bit of search and have the only mention of this seems to include the following code, but I can't find any documentation about it, any ideas?

<?php wp_enqueue_script("jquery"); ?>
Denis Otkidach
  • 32,032
  • 8
  • 79
  • 100
Nick
  • 382
  • 1
  • 8
  • 26

4 Answers4

5

As of WordPress 3.3, this is the best way to do it, using the proper hook:

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
    wp_enqueue_script('jquery');
}
JimSteinhart
  • 160
  • 1
  • 10
0

you need to include the following code before <?php wp_head(); ?> in your header.php

<?php wp_enqueue_script("jquery"); ?>

and you can remove other jquery includes from header.php

Aram Mkrtchyan
  • 2,690
  • 4
  • 31
  • 47
0

In addition to what Aram Mkrtchyan said, you can enqueue your scripts also using wp_enqueue_script().

<?php
    wp_enqueue_script('jquery');
    wp_enqueue_script('your_script', "path/to/your/script.js" , array('jquery'));
?>

The third argument to wp_enqueue_script() tells WordPress that your_script is dependent on jquery, so load it only after jquery has loaded.

ronakg
  • 4,038
  • 21
  • 46
0

Actually, you need to use admin_init hook to make it work in admin section:

function jquery_for_admin() {
  wp_enqueue_script('jquery');
  return;
}

add_action('admin_init', 'jquery_for_admin');
Oleksandr Skrypnyk
  • 2,762
  • 1
  • 20
  • 25