2
function banana_scripts() {     
    wp_enqueue_script('grid', get_stylesheet_directory_uri() . '/js/jquery.min.js', null, null);
    wp_enqueue_script('grid', get_stylesheet_directory_uri() . '/js/main.js', null, null);
}   
add_action('wp_enqueue_scripts', 'banana_scripts');

I have the above hook in my functions.php. The first js file gets included, the second not. Is it incorrect to call this function twice or more?

  • 1
    Any feedback on your previous issue with sticky posts. :-) – Pieter Goosen Jun 23 '15 at 11:39
  • @Thank, I have seen your code, but I am not yet as far as to implement it immediately, I am cleaning up what I have so far, and need to fix some basic issues like scripts and styles. – Drunken Master Jun 23 '15 at 11:55
2

You gave each each script the same handle/id of 'grid'

Try something like this.

function banana_scripts() {     
    wp_enqueue_script('grid', get_stylesheet_directory_uri() . '/js/jquery.min.js', null,   null);
    wp_enqueue_script('grid2', get_stylesheet_directory_uri() . '/js/main.js', null, null);
}   
add_action('wp_enqueue_scripts', 'banana_scripts');
  • Thanks, apparently it's not a good idea to copy-paste things, the 'handle' of the script is something I have skipped to change, I see what caused the conflict now. I have decided anyway to link jquery from an external source, but many thanks for this solution. – Drunken Master Jun 23 '15 at 11:58
  • 1
    make sure when you link to an external resource to exclude the protocol. This will help conflicts if your site is http or https. example: wp_enqueue_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'); – David Labbe Jun 23 '15 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.