How to enqueue second stylesheet in Wordpress child theme?

本小妞迷上赌 提交于 2019-12-11 13:53:50

问题


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

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

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/35638653/how-to-enqueue-second-stylesheet-in-wordpress-child-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!