[英]How do I include JQuery and Bootstrap.min.js in Wordpress?
This has been asked before but I am still struggling with understanding it. 之前曾有人问过这个问题,但我仍在努力理解它。
I have wp_head() in my header.php file in the <HEAD> </HEAD>
. 我在
<HEAD> </HEAD>
header.php文件中有wp_head()。
In my functions.php I have: 在我的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' );
?>
In js/ I have bootstrap.min.js and jquery-1.11.0.min.js. 在js /中,我有bootstrap.min.js和jquery-1.11.0.min.js。
The reason I know it isn't working is because I have a carousel in bootstrap which isn't running, as it requires bootstrap.min.js. 我知道它不起作用的原因是因为我在bootstrap中有一个未运行的轮播,因为它需要bootstrap.min.js。
Many thanks!!! 非常感谢!!!
You need a '/' before 'js', like 您需要在“ js”之前添加“ /”,例如
get_template_directory_uri() . '/js/bootstrap.min.js',
get_stylesheet_directory_uri() is the same way. get_stylesheet_directory_uri()是相同的方法。 These functions return a uri without a trailing slash.
这些函数返回一个URI, 且不带斜杠。
Your js is loaded correctly. 您的js已正确加载。 You should just make sure that it is in the js folder.
您只需要确保它在js文件夹中即可。 Another point to take note of, if you are using a child theme, you should use
get_stylesheet_directory_uri
. 要注意的另一点是,如果您使用的是子主题,则应使用
get_stylesheet_directory_uri
。 For more info refer to the codex 有关更多信息,请参阅法典
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.