簡體   English   中英

Wordpress:帶有bootstrap和wordpress的JavaScript插件

[英]Wordpress: JavaScript plugin with bootstrap and wordpress

所以我無法讓燈箱插件的js正常工作。 我得到的錯誤是:

未捕獲的TypeError:undefined不是函數bootstrap-lightbox.js?ver = 4.1:113

我的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');

然后我在header.php中有這個

<?php wp_enqueue_script( 'jquery' ) ?>

我可以發現什么是錯的。 我一直在谷歌搜索幾個小時,我找到的修復程序都沒有為我工作(或者理解它們可能是另一個原因)。

我認為你不需要在你的標題中排隊jQuery,WordPress會自動處理它,因為它被列為bootstrapjs的依賴項。 另外,您應該將bootstrapjs列為bootstraplightbox的依賴項,如下所示:

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

這將確保在bootstraplightbox之前加載bootstrapjs文件,因為我假設必須發生。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM