0

I am using the function.php files wp_enqueue_script function to load in my .js files.

However even though I believe I load jQuery before the slick.js. Slick returns an error in my console 'jQuery is not defined' in slick.min.js. All documents exist and are in the correct location.

function hubble_space_scripts() {
    wp_deregister_script('jquery');
    wp_enqueue_script('custom-jquery', get_template_directory_uri() . '/js/jquery-3-4-1.js', array(), null, true);
    wp_enqueue_script('slick-scripts', get_template_directory_uri() . '/js/slick.js', array(), null, true);

    wp_enqueue_script( 'hubble-space-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
    wp_enqueue_script( 'hubble-space-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
    wp_enqueue_script('pretty-photo-scripts', get_template_directory_uri() . '/js/pretty-photo.js', array(), null, true);
    wp_enqueue_script( 'hubble-space-theme-script', get_template_directory_uri() . '/js/hubble-space.min.js', array(), '20151215', true );
    wp_enqueue_script('ajax-pagination-scripts', get_template_directory_uri() . '/js/ajax-pagination.js', array(), null, true);
    wp_enqueue_script('footer-scripts', get_template_directory_uri() . '/js/footer-scripts.js', array(), null, true);
}
add_action('wp_enqueue_scripts', 'hubble_space_scripts');

Why is this happening? If you could let me know the parts I can copy into my question that are relevant I am happy to provide further resources. Not sure how complex the answer to this question is yet.

Thank you to all contributors, Jason.

  • 2
    Why are you deregistering WP's jquery? If you have to go that route, you should dequeue it too, replacing WP's jquery is generally not a good practice though. Anyway, you should specify the dependencies for each of the scripts. They probably depend on jquery or in this case custom-jquery See the $deps argument here developer.wordpress.org/reference/functions/wp_enqueue_script – Dave Romsey Jan 31 at 15:33
  • I have removed the call to my own version of jQuery – Jason Is My Name Jan 31 at 15:42
  • Removed jQuery that comes with WordPress is generally a very bad idea because plugins are mostly made to work with that specific jQuery version (even if it is very much outdated). If you need to remove it, replace it properly by replacing the default registered jQuery script. – Milan Petrovic Jan 31 at 16:02
  • Good idea, is that as simple as finding the copy within the theme files and replacing it? Or is it done through a CDN and I would need to change the URL? – Jason Is My Name Jan 31 at 18:04
1

Long shot, but aren't you by any chance typing $ instead of jQuery, or vice versa?

(function($) {    
    // Use $() inside of this function    
    $('#selector') ...    
})(jQuery);

or

// Otherwise use jQuery()
jQuery('#selector') ...
| improve this answer | |
  • Stupids of me, but yeah I had a mix of $ and jQuery in use... – Jason Is My Name Jan 31 at 15:42

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.