如何将第二个样式表排入Wordpress子主题? [英] How to enqueue second stylesheet in Wordpress child theme?

查看:185
本文介绍了如何将第二个样式表排入Wordpress子主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using a child theme and need to enqueue the stylesheet for a slider. The css file is located in a folder in the parent theme directory, i.e. /parent-theme/css/flexislider.css

我使用插件添加了一个 functions.php 文件到子主题目录中创建了子主题,代码如下:

I created the child theme using a plugin which added a functions.php file to the child theme directory with the following code:

<?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')
);
}



我假设我必须在上述函数中添加另一个条目, $ c> flexislider.css 但我不太确定如何做。

I assume I have to add another entry to the above function referencing flexislider.css but I'm not quite sure how to do it.

推荐答案

* UPDATED

*UPDATED

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

Based on what you added to the question, you should be able to just add to that function and register the stylesheet. The full function would look like this:

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代码位于

I don't have much experience with child-themes, but following the model in that function, I think get_template_directory points to the parent theme and not the child theme, which you said the flexislider code is located

这篇关于如何将第二个样式表排入Wordpress子主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆