【问题标题】:How to enqueue second stylesheet in Wordpress child theme?如何在 Wordpress 子主题中将第二个样式表排入队列?
【发布时间】:2016-02-25 21:25:02
【问题描述】:

我正在使用子主题,需要将样式表排入队列以获取滑块。 css文件位于父主题目录下的一个文件夹中,即/parent-theme/css/flexislider.css

我使用插件创建了子主题,该插件使用以下代码将functions.php 文件添加到子主题目录:

<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',get_stylesheet_directory_uri() . '/style.css',array('parent-style')
);
}

我假设我必须在引用 flexislider.css 的上述函数中添加另一个条目,但我不太确定该怎么做。

【问题讨论】:

    标签: css wordpress-theming


    【解决方案1】:

    *已更新

    根据您添加到问题中的内容,您应该能够添加到该函数并注册样式表。完整的功能如下所示:

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',get_stylesheet_directory_uri() . '/style.css',array('parent-style')
    );
    wp_enqueue_style('flex-slider',get_template_directory_uri() . '/css/flexislider.css');
    }
    

    我对子主题没有太多经验,但是按照该函数中的模型,我认为get_template_directory 指向父主题而不是您所说的flexislider代码所在的子主题

    【讨论】:

    • 您好,感谢您的回答。我仍然不太确定如何做到这一点。我刚刚用更多细节更新了我的问题,这可能会帮助您更具体地回答。
    • 我更新了答案以包含您更新的问题
    • 谢谢,我认为这也可以,但事实并非如此。你说,“......并注册样式表”。我还需要注册样式表吗?是分开做的吗?
    • 抱歉,我的代码出现格式错误,现在滑块显示正确。再次感谢您的帮助。
    • 太棒了!祝你网站好运。如果它对您的问题有帮助,请接受此答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多