![](/img/trans.png)
[英]bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery at bootstrap.min.js:6
[英]How do I include JQuery and Bootstrap.min.js in Wordpress?
之前曾有人問過這個問題,但我仍在努力理解它。
我在<HEAD> </HEAD>
header.php文件中有wp_head()。
在我的functions.php中,我有:
<?php
function my_scripts_method() {
wp_enqueue_script(
'custom-script',
get_template_directory_uri() . 'js/bootstrap.min.js',
array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
?>
在js /中,我有bootstrap.min.js和jquery-1.11.0.min.js。
我知道它不起作用的原因是因為我在bootstrap中有一個未運行的輪播,因為它需要bootstrap.min.js。
非常感謝!!!
您需要在“ js”之前添加“ /”,例如
get_template_directory_uri() . '/js/bootstrap.min.js',
get_stylesheet_directory_uri()是相同的方法。 這些函數返回一個URI, 且不帶斜杠。
您的js已正確加載。 您只需要確保它在js文件夾中即可。 要注意的另一點是,如果您使用的是子主題,則應使用get_stylesheet_directory_uri
。 有關更多信息,請參閱法典
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.