functions - wp_enqueue_script | Help me figure out what is causing jQuery is not defined

I am using the function.php files wp_enqueue_script function to load in my .js files.However even though I believe I loa

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.

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.

Share Improve this question asked Jan 31, 2020 at 15:26 Jason Is My NameJason Is My Name 3782 gold badges7 silver badges21 bronze badges 4
  • 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/reference/functions/wp_enqueue_script – Dave Romsey Commented Jan 31, 2020 at 15:33
  • I have removed the call to my own version of jQuery – Jason Is My Name Commented Jan 31, 2020 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 Commented Jan 31, 2020 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 Commented Jan 31, 2020 at 18:04
Add a comment  | 

1 Answer 1

Reset to default 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') ...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744786637a4593665.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信