3
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?

2
  • 1
    Any feedback on your previous issue with sticky posts. :-) Commented Jun 23, 2015 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.
    – imrek
    Commented Jun 23, 2015 at 11:55

1 Answer 1

4

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

Try something like this.

function banana_scripts() {     
    wp_enqueue_script('grid-jq', get_stylesheet_directory_uri() . '/js/jquery.min.js', null,   null);
    wp_enqueue_script('grid-main', get_stylesheet_directory_uri() . '/js/main.js', null, null);
}   
add_action('wp_enqueue_scripts', 'banana_scripts');
2
  • 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.
    – imrek
    Commented Jun 23, 2015 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'); Commented Jun 23, 2015 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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