questions

wp_enqueue_script() wordpress problem with any scrips

Rate this post

I´m traying to create a personaliced theme in wordpress, and i have a function to enqueue my scripts, but when i´m ending to add my scripts and load my web in my console.

QMIGRATE: Migrate is installed, version 3.3.2
mouse.min.js?ver=5.6:11 Uncaught TypeError: o.widget is not a function
    at mouse.min.js?ver=5.6:11
    at mouse.min.js?ver=5.6:11
    at mouse.min.js?ver=5.6:11
(anonymous) @ mouse.min.js?ver=5.6:11
(anonymous) @ mouse.min.js?ver=5.6:11
(anonymous) @ mouse.min.js?ver=5.6:11
jquery.selectBoxIt.min.js?ver=5.6:4 Uncaught TypeError: a.widget is not a function
    at jquery.selectBoxIt.min.js?ver=5.6:4
    at jquery.selectBoxIt.min.js?ver=5.6:4
    at jquery.selectBoxIt.min.js?ver=5.6:4
(anonymous) @ jquery.selectBoxIt.min.js?ver=5.6:4
(anonymous) @ jquery.selectBoxIt.min.js?ver=5.6:4
(anonymous) @ jquery.selectBoxIt.min.js?ver=5.6:4
main.js?ver=5.6:1 Uncaught TypeError: $ is not a function
    at main.js?ver=5.6:1
(anonymous) @ main.js?ver=5.6:1
2VM5192 bs-navbar.js:2 Uncaught TypeError: $ is not a function
    at VM5192 bs-navbar.js:2
(anonymous) @ VM5192 bs-navbar.js:2
widget.min.js?ver=5.6:11 Uncaught TypeError: i is not a constructor
    at Function.h.widget (widget.min.js?ver=5.6:11)
    at slider.min.js?ver=5.6:11
    at slider.min.js?ver=5.6:11
    at slider.min.js?ver=5.6:11

and i don´t know that i´m doing wrong. This is my function in function.php. I think that i´m enqueue my scripts well but i don´t know if i have to follow one order or not

function scriptsWeb() {

    wp_register_script('jquery', get_template_directory_uri().'/js/jquery/jquery.js', array('jquery'), false, true);
    wp_enqueue_script('jquery');
    wp_register_script('jquery2', get_template_directory_uri().'/js/jquery.js', array('jquery'), false, true);
    wp_enqueue_script('jquery2');
    wp_register_script('core', get_template_directory_uri().'/js/jquery/ui/core.min.js', array('jquery'), false, true);
    wp_enqueue_script('core');

    wp_register_script('datepicker', get_template_directory_uri().'/js/jquery/ui/datepicker.min.js', array('jquery'), false, true);
    wp_enqueue_script('datepicker');
    wp_register_script('position', get_template_directory_uri().'/js/jquery/ui/position.min.js', array('jquery'), false, true);
    wp_enqueue_script('position');

    wp_register_script('imagesloaded', get_template_directory_uri().'/js/imagesloaded.min.js', array('jquery'), false, true);
    wp_enqueue_script('imagesloaded');

    wp_register_script('jquerysticky', get_template_directory_uri().'/js/jquery.sticky.js', array('jquery'), false, true);
    wp_enqueue_script('jquerysticky');
    
    wp_register_script('datepicker', get_template_directory_uri().'/js/jquery/ui/datepicker.min.js', array('jquery'), false, true);
    wp_enqueue_script('datepicker');

    wp_register_script('mouse', get_template_directory_uri().'/js/jquery/ui/mouse.min.js', array('jquery'), false, true);
    wp_enqueue_script('mouse');
    
    wp_register_script('position', get_template_directory_uri().'/js/jquery/ui/position.min.js', array('jquery'), false, true);
    wp_enqueue_script('position');
    
    wp_register_script('imagesLoader', get_template_directory_uri().'/js/imagesloaded.min.js', array('jquery'), false, true);
    wp_enqueue_script('imagesLoader');

    wp_register_script('underscore', get_template_directory_uri().'/js/underscore.min.js', array('jquery'), false, true);
    wp_enqueue_script('underscore');

    wp_register_script('wp-embed', get_template_directory_uri().'/js/wp-embed.js', array('jquery'), false, true);
    wp_enqueue_script('wp-embed');

    wp_register_script('wp-util', get_template_directory_uri().'/js/wp-util.js', array('jquery'), false, true);
    wp_enqueue_script('wp-util');

    wp_register_script('bootstrap', get_template_directory_uri().'/js/bootstrap.min.js', array('jquery'), false, true);
    wp_enqueue_script('bootstrap');

    wp_register_script('slick', get_template_directory_uri().'/js/vendors/slick/slick.min.js', array('jquery'), false, true);
    wp_enqueue_script('slick');

    wp_register_script('carousel', get_template_directory_uri().'/plugin/owl-carousel/owl.carousel.min.js', array('jquery'), false, true);
    wp_enqueue_script('carousel');
   
    wp_register_script('isotope', get_template_directory_uri().'/js/vendors/isotope/isotope.pkgd.js', array('jquery'), false, true);
    wp_enqueue_script('isotope');

    wp_register_script('tweecool', get_template_directory_uri().'/js/vendors/tweets/tweecool.min.js', array('jquery'), false, true);
    wp_enqueue_script('tweecool');

    wp_register_script('rs-plugin', get_template_directory_uri().'/js/vendors/rs-plugin/js/jquery.themepunch.revolution.min.js', array('jquery'), false, true);
    wp_enqueue_script('rs-plugin');

    wp_register_script('themepunch.tools', get_template_directory_uri().'/js/vendors/rs-plugin/js/jquery.themepunch.tools.min.js', array('jquery'), false, true);
    wp_enqueue_script('themepunch.tools');

    wp_register_script('sticky', get_template_directory_uri().'/js/jquery.sticky.js', array('jquery'), false, true);
    wp_enqueue_script('sticky');

    wp_register_script('subscribe-better', get_template_directory_uri().'/js/jquery.subscribe-better.js', array('jquery'), false, true);
    wp_enqueue_script('subscribe-better');

    wp_register_script('selectBoxIt', get_template_directory_uri().'/js/vendors/select/jquery.selectBoxIt.min.js', array('jquery'), false, true);
    wp_enqueue_script('selectBoxIt');

    wp_register_script('main', get_template_directory_uri().'/js/main.js', array('jquery'), false, true);
    wp_enqueue_script('main');
    
    wp_register_script('navbar', get_template_directory_uri().'/js/bs-navbar.js', array('jquery'), false, true);
    wp_enqueue_script('navbar');

    wp_register_script('royalslider', get_template_directory_uri().'/js/royalslider/jquery.royalslider.min.js', array('jquery'), false, true);
    wp_enqueue_script('royalslider');

    wp_register_script('bs-nav', get_template_directory_uri().'/js/bs-navbar.js', array('jquery'), false, true);
    wp_enqueue_script('bs-nav');

    wp_register_script('widget', get_template_directory_uri().'/js/jquery/ui/widget.min.js', array('jquery'), false, true);
    wp_enqueue_script('widget');

    wp_register_script('slider', get_template_directory_uri().'/js/jquery/ui/slider.min.js', array('jquery'), false, true);
    wp_enqueue_script('slider');
}

add_action('wp_enqueue_scripts', 'stylesWeb');
add_action('wp_enqueue_scripts', 'scriptsWeb');
add_action( 'wp_enqueue_scripts', 'add_font_awesome' );

 

✔️Solution:

Have you tried using wp_register_script and add_action?

For example:

/* Always use wp_enqueue_scripts action hook to both enqueue and register scripts */
add_action('wp_enqueue_scripts', 'enqueue_and_register_my_scripts');
function enqueue_and_register_my_scripts() {
  $template_uri = get_template_directory_uri(); /* No need to call this function every time 😉 */
        
  wp_register_script('datepicker',  $template_uri . '/js/jquery/ui/datepicker.min.js', array('jquery'), null, false);
  wp_enqueue_script('datepicker');
}

Also: jQuery is alreay bundled with WordPress, there is no need to add it.

Leave a Reply

Your email address will not be published.

Back to top button