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"); ?>

4 Answers 4

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');
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks looks great, am I correct in thinking this would go in my themes functions.php? Many thanks!
No problem. You're right, this goes in your themes function.php
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

7 Comments

Thanks, however this seems to load in jquery last which in turn means that my other scripts don't initialise correctly, they are included at the bottom of the head as "<script src="/wp-content/themes/themename/js/scripts.js"></script>" any ideas?
include this line before your script includes
I currently have the following which doesn't seem to work: <?php wp_enqueue_script("jquery"); ?> <?php wp_head(); ?> <script src="/wp-content/themes/eog/js/jquery.ticker.js"></script> <script src="/wp-content/themes/eog/js/jquery.cycle.lite.js"></script> <script src="/wp-content/themes/eog/js/scripts.js"></script>
can you check if jquery is included or not ?
it seems to be included but is loaded last when using the enqueue script
|
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.

Comments

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');

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.