![](/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.