【问题标题】:Can't import bootstrap in wordpress无法在 wordpress 中导入引导程序
【发布时间】:2017-02-19 01:31:59
【问题描述】:

我在将 boostrap 添加到 wordpress 子主题时遇到问题。

这是我的文件夹在子主题中的外观: http://i.imgur.com/vuOvYJ3g.jpg

并且有来自 css 文件夹的内容 http://i.imgur.com/AsQAi3r.jpg

在function.php中我试过这个:

function theme_add_bootstrap() {
    wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css' );
    wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css' );
    wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array(), '3.0.0', true );
}

add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap' );

但不起作用,在 index.php 中我写了 class col-sm-3 并在 Chrome 的检查元素中没有从引导程序中读取类和样式。

你能帮帮我吗,非常感谢!

【问题讨论】:

    标签: php css wordpress twitter-bootstrap


    【解决方案1】:

    要加载子主题的资源,请使用 get_stylesheet_directory_uri 函数而不是 get_template_directory_uri 函数。

    function theme_add_bootstrap() {
      wp_enqueue_style( 'bootstrap-css', get_stylesheet_directory_uri() . '/css/bootstrap.min.css' );
      wp_enqueue_style( 'style-css', get_stylesheet_directory_uri() . '/style.css' );
      wp_enqueue_script( 'bootstrap-js', get_stylesheet_directory_uri() . '/js/bootstrap.min.js', array(), '3.0.0', true );
    }
    
    add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap' );
    

    您也可以查看 WordPress Child Theme 了解更多信息。

    【讨论】:

    • 您可以通过打开浏览器开发者工具来验证文件是否加载成功,然后导航到网络选项卡,专门过滤您要检查的资产。这样就可以验证资产是否加载成功了。
    • 它是附加的图像,过滤器是用于图像的,因此选择的过滤器是用于IMG的,尝试点击CSS,JS过滤器,然后刷新页面。
    • sorry 错误的附加图像,我也尝试了 js 和 css 相同的结果:(
    • 请阅读 WordPress Child Themes 的文档,这是一份详尽的文档,因此阅读指南有 100% 的机会解决您的问题。伟大的开发者总是从阅读他们特定工具集的官方文档开始。
    • 嗯,我已经创建了子主题。复制必要的 instyle.css 并调用 URI 等...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 2021-12-01
    • 2018-04-25
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多