Wordpress: only upload one jquery script per website

Just started the WordPress site, but noticed that it is currently loading in two jquery files, one from wp-includes and one from mine header.php

, is there a way to make Wordpress load wp-include one on frontend? Quite a bit of searching has been done and the only mention of it seems to include the following code, but I can't find any documentation on this, any ideas?

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

      

+1


source to share


4 answers


As of WordPress 3.3, this is the best way to do it using the correct 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');
}

      

+4


source


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

in header.php

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

      



and you can remove other jquery from header.php

0


source


In addition to what Aram Mkrtchyan said, you can insert your scripts into the queue with wp_enqueue_script()

.

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

      

The third argument wp_enqueue_script()

tells WordPress what it your_script

depends on jquery

, so only load it after loading jquery

.

0


source


You actually need to use a admin_init

hook for it to work in the admin section:

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

add_action('admin_init', 'jquery_for_admin');

      

0


source







All Articles