简体   繁体   English

Wordpress:带有bootstrap和wordpress的JavaScript插件

[英]Wordpress: JavaScript plugin with bootstrap and wordpress

So I cant get the js for a lightbox plugin to work correctly. 所以我无法让灯箱插件的js正常工作。 The error I get is: 我得到的错误是:

Uncaught TypeError: undefined is not a function bootstrap-lightbox.js?ver=4.1:113 未捕获的TypeError:undefined不是函数bootstrap-lightbox.js?ver = 4.1:113

My functions.php: 我的functions.php:

function bootstrap_js() {


wp_enqueue_script( 'bootstrapjs', get_stylesheet_directory_uri() .         '/js/bootstrap.js', array('jquery'), '', true );

wp_enqueue_script( 'bootstraplightbox', get_stylesheet_directory_uri() . '/js/bootstrap-lightbox.js', array('jquery'), '', true );

}

add_action( 'wp_enqueue_scripts', 'bootstrap_js');

And then I have this in my header.php 然后我在header.php中有这个

<?php wp_enqueue_script( 'jquery' ) ?>

I can find out whats wrong. 我可以发现什么是错的。 I have been googling for hours now and none of the fixes I have found has worked for me (or understood them might be another reason). 我一直在谷歌搜索几个小时,我找到的修复程序都没有为我工作(或者理解它们可能是另一个原因)。

I don't think you need the line to enqueue jQuery in your header, WordPress will handle that automagically as it is listed as a dependency of bootstrapjs. 我认为你不需要在你的标题中排队jQuery,WordPress会自动处理它,因为它被列为bootstrapjs的依赖项。 Additionally, you should probably list bootstrapjs as a dependency of bootstraplightbox like so: 另外,您应该将bootstrapjs列为bootstraplightbox的依赖项,如下所示:

wp_enqueue_script( 'bootstraplightbox', get_stylesheet_directory_uri() . '/js/bootstrap-lightbox.js', array('jquery', 'bootstrapjs'), '', true );

This will make sure that the bootstrapjs file is loaded before bootstraplightbox, as I am assuming that must happen. 这将确保在bootstraplightbox之前加载bootstrapjs文件,因为我假设必须发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM