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"); ?>
source to share
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');
}
source to share
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
.
source to share