I have WordPress 3.9 running on local (MampPro) and below a portion of functions.php
containing the code to load jquery and other js in the footer.
The problem is that I am getting jquery to be loaded twice. One in the header and one in the footer. I am a bit confused to figure out why!
<?php
/**
* Enqueue JS - http://eamann.com/tech/dont-dequeue-wordpress-jquery/
*/
function zero_script() {
if (!is_admin()) {
wp_deregister_script('jquery');
//wp_register_script('modernizr', get_template_directory_uri() . '/dist/js/lib/modernizr- 2.7.0.min.js', array(), null, false);
wp_register_script('main_js', get_template_directory_uri() . '/dist/js/main.min.js', array('jquery'), '', true);
//wp_enqueue_script('modernizr');
wp_enqueue_script( 'jquery', '/wp-includes/js/jquery/jquery.js', '', '', true );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'main_js' );
}
}
add_action('wp_enqueue_scripts', 'zero_script'); // initiate the function
**SOLVED***
I am building a WP Theme from scratch and the only plugin installed is “iThemes Security”
with checked the option:
It was burried in all the options…I have unchecked that option and now I have jquery called once, in the footer.
The First jquery call (in head was called by IThemes and the second in the footer from me)
I did some amend to the file so it is more clear what is happening:
Try taking out
wp_enqueue_script( 'jquery' );
EDIT: try changing
wp_enqueue_script( 'jquery', '/wp-includes/js/jquery/jquery.js', '', '', true );
to
wp_register_script( 'jquery', '/wp-includes/js/jquery/jquery.js', '', '', true );
and keep
wp_enqueue_script( 'jquery' );
Okay EDIT2:
Edit:3
you are calling it twice………….
you just need
as wordpress has jquery ready to be used 🙂