简体   繁体   English

如何在Wordpress中包含JQuery和Bootstrap.min.js?

[英]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.

相关问题 bootstrap.min.js:6未捕获的错误:Bootstrap的JavaScript需要bootstrap.min.js:6上的jQuery - bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery at bootstrap.min.js:6 未捕获的错误引导程序需要 bootstrap.min.js 中的 jquery - uncaught error bootstrap requires jquery at bootstrap.min.js 如何在 ember-bootstrap 插件中加载 bootstrap.min.js - How to load bootstrap.min.js in ember-bootstrap plugin bootstrap.min.js中的意外标记 - Unexpected token in bootstrap.min.js Chrome在bootstrap.min.js中显示错误 - Chrome shows error in bootstrap.min.js bootstrap.min.js的src无法正常工作 - src of Bootstrap.min.js not working bootstrap.min.css 和 bootstrap.min.js 的 404 错误 - 404 error for bootstrap.min.css and bootstrap.min.js 未捕获的错误:Bootstrap 的 JavaScript 需要 electron 应用程序中 bootstrap.min.js:6 处的 jQuery - Uncaught Error: Bootstrap's JavaScript requires jQuery at bootstrap.min.js:6, in an electron app bootstrap.min.JS 是否与 chart.min,js 冲突? - Does bootstrap.min.JS conflict with chart.min,js? 引导反应。/node_modules/bootstrap/dist/js/bootstrap.min.js 找不到模块:无法解析“jquery” - Bootstrap react ./node_modules/bootstrap/dist/js/bootstrap.min.js Module not found: Can't resolve 'jquery'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM