这之前已经问过了,但我仍然在努力理解它。
我的头.php文件中有 wp_head(),<HEAD> </HEAD>
中的文件。
在我的职能中.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.min.js。
非常感谢!!
你需要在"js"之前加上"/",比如
get_template_directory_uri() . '/js/bootstrap.min.js',
get_stylesheet_directory_uri() 是相同的方式。这些函数返回不带尾部斜杠的 URI。
你的 js 已正确加载。你应该确保它在js文件夹中。另一点需要注意的是,如果您使用的是子主题,则应使用 get_stylesheet_directory_uri
.有关更多信息,请参阅法典