2017-07-06 23:28
采纳率: 0%
浏览 105


I am trying to run a lightbox plugin in WordPress. For some reason it will not load and I have the correct file path. Normally I use the cdn version of files, but there is not a such version around and I have to load it locally. I also have some violations. I have no idea what is going on and why I am receiving the error.


function nutrition_club_theme_script_enqueue() {

 wp_enqueue_script('jquery', '');

    wp_enqueue_script('jquery-tools', get_template_directory_uri() .'/js/', array('jquery'), '', true);

    wp_enqueue_script('jquery-portfoliolightbox', get_template_directory_uri() .'/js/jquery.portfoliolightbox.js', '', '', true);

    wp_enqueue_script('jquery-magnific-popup', '');

    wp_enqueue_script('customjs', get_template_directory_uri() . '/js/nutrition_club_theme.js', array('jquery'), '4.8', false);

    wp_enqueue_script('owljs', '');

    wp_enqueue_script('bootstrapjs', get_template_directory_uri() . '/js/bootstrap.min.js', array(), '3.3.7', true);

    wp_enqueue_script('popup-galleryjs', get_template_directory_uri() . '/js/popup-gallery.js', array(), '', true);

    wp_enqueue_script('wowjs', '');


add_action(wp_enqueue_scripts, 'nutrition_club_theme_script_enqueue');


    imgpath: '',
    title: 'Your Title',
    text: 'Enter any text',
    link: ['', ''],
    linkText: ['Site 1 Text', 'Link 2 text']

Chrome error

Uncaught TypeError: jquery-3.2.1.min.js?ver=3.2.1:2 
jQuery(...).lightBox is not a function
        at HTMLDocument.<anonymous> (nutrition_club_theme.js?ver=4.8:81)
        at j (jquery-3.2.1.min.js?ver=3.2.1:2)
        at k (jquery-3.2.1.min.js?ver=3.2.1:2)
    (anonymous) @ nutrition_club_theme.js?ver=4.8:81
    j @ jquery-3.2.1.min.js?ver=3.2.1:2
    k @ jquery-3.2.1.min.js?ver=3.2.1:2


[Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive.
jquery-3.2.1.min.js?ver=3.2.1:2 [Violation] 'setTimeout' handler took 341ms
[Violation] Forced reflow while executing JavaScript took 197ms
[Violation] Forced reflow while executing JavaScript took 65ms
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dousong5161 2017-07-07 00:58

    You are loading custom.js before the Lightbox script.

    Try adding extra dependencies to your enqueue

    wp_enqueue_script('customjs', get_template_directory_uri() . '/js/nutrition_club_theme.js', array('jquery', 'jquery-portfoliolightbox', 'jquery-magnific-popup'), '4.8', false);

    Or whatever the script adding the lightBox is. You should always make sure you set dependencies correctly to avoid this.

    NOTE: you should also make sure that if there is an enqueued script ( like the lightBox one ) that requires jQuery, has it set as a dependency.

    打赏 评论

相关推荐 更多相似问题