【问题标题】:Why the styles are not being applied to the wordpress custom theme?为什么样式没有应用于 wordpress 自定义主题?
【发布时间】:2019-11-04 10:24:03
【问题描述】:

我从 w3layouts 下载了一个模板。我希望这个模板显示为 wordpress 主题。我已经将 index.html 转换为 index.php 并且 style.css 和 index.php 都在同一个目录中,我还使用了 php 的 bloginfo() 函数。这是我的 index.php 的 head 部分

<link rel="icon" href="<?php bloginfo('img/favicon.png')?>" />
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="<?php bloginfo('bootstrap.min.css')?>" />
    <!-- animate CSS -->
    <link rel="stylesheet" href="<?php bloginfo('animate.css')?>" />
    <!-- owl carousel CSS -->
    <link rel="stylesheet" href="<?php bloginfo('owl.carousel.min.css')?>" />
    <!-- themify CSS -->
    <link rel="stylesheet" href="<?php bloginfo('themify-icons.css')?>" />
    <!-- flaticon CSS -->
    <link rel="stylesheet" href="<?php bloginfo('flaticon.css')?>" />
    <!-- font awesome CSS -->
    <link rel="stylesheet" href="<?php bloginfo('magnific-popup.css')?>" />
    <!-- swiper CSS -->
    <link rel="stylesheet" href="<?php bloginfo('slick.css')?>" />
    <!-- style CSS -->
    <link rel="stylesheet" href="<?php bloginfo('style.css')?>" />

我已将我的模板文件夹放在 wordpress 的主题文件夹中。 index.php 和 style.css 都在 css 文件夹中。我是wordpress的新手。提前致谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    在你的functions.php文件中添加这个:
    /resources/css/ 是您的样式的路径。

    define( 'THEME_DIR', get_template_directory_uri() )
    
    wp_enqueue_style( 'main-style-css', THEME_DIR . '/resources/css/style.css' );
    

    稍后在 HTML 模板的 head 标签中添加

    <head>
    // ... ...
    wp_head();
    
    </head>
    

    【讨论】:

    • 我没有 functions.php 文件。它是什么?它应该在哪里?
    猜你喜欢
    • 2017-05-09
    • 2017-05-11
    • 2023-04-02
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多