Jquery on wordpress still loading in header

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

Related posts

Leave a Reply

3 comments

  1. **SOLVED***

    I am building a WP Theme from scratch and the only plugin installed is “iThemes Security”
    with checked the option:

    “Enqueue a safe version of jQuery”
    Remove the existing jQuery version used and replace it with a safe version (the version that comes default with WordPress).

    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:

    <?php
    /**
    * Enqueue JS - http://eamann.com/tech/dont-dequeue-wordpress-jquery/
    */
    
    function zero_script() {
    
     if (!is_admin()) {
    
      //Call Modernizr
      //wp_register_script('modernizr', get_template_directory_uri() .  '/dist/js/lib/modernizr-custom.min.js', array(), null, false);
      //wp_enqueue_script('modernizr');
    
      //Call JQuery
      wp_deregister_script('jquery');
      wp_register_script( 'jquery', '/wp-includes/js/jquery/jquery.js', '', '', true);
      wp_enqueue_script( 'jquery' );
    
    
      //Call Custom js file
      wp_register_script('main_js', get_template_directory_uri() . '/dist/js/main.min.js', array('jquery'), '', true);
      wp_enqueue_script( 'main_js' );
    
     }
    
    }
    
    add_action('wp_enqueue_scripts', 'zero_script'); // Initiate the function
    
  2. 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:

    wp_deregister_script('jquery');
    wp_register_script( 'jquery', '/wp-includes/js/jquery/jquery.js', '', '', true );
    wp_register_script('main_js', get_template_directory_uri() . '/dist/js/main.min.js',   array('jquery'), '', true);
    wp_enqueue_script( 'main_js' );
    

    Edit:3

    function zero_script() {
    wp_deregister_script('jquery');
    wp_register_script( 'jquery', '/wp-includes/js/jquery/jquery.js', '', '', true );
    if (!is_admin()) {
    wp_register_script('main_js', get_template_directory_uri() . '/dist/js/main.min.js',   array('jquery'), '', true);
    wp_enqueue_script( 'main_js' );
    }
    }
    
  3. you are calling it twice………….

     wp_enqueue_script( 'jquery', '/wp-includes/js/jquery/jquery.js', '', '', true );
     wp_enqueue_script( 'jquery' );
    

    you just need

        wp_enqueue_script( 'jquery' );
    

    as wordpress has jquery ready to be used 🙂