子主题中的多个 .css 文件

Dam*_*mir 3 html css wordpress

首先在 WP 中使用子主题。

我在 themes 文件夹中创建了一个名为 my-theme-name-child 的新文件夹,并放置了 style.css 文件。

现在,原始主题有一个响应式样式表,它位于 my-theme-name/css/layout.css 如何在我的子主题中复制它?

我在我的子主题中创建了文件夹 css 并在那里创建了 layout.css ,如下所示:

@import url("../my-original-theme/css/layout.css");

@media only screen and (min-width: 769px)

#header {
    padding: 20.618em 0 !important;
}
Run Code Online (Sandbox Code Playgroud)

Wis*_*abs 5

layout.css子主题的 css 文件夹中创建后,您必须在子主题的function.phpcss 文件夹中编写以下函数,才能加载它:

function load_child_stylesheet() {
    wp_enqueue_style( 'layout', get_stylesheet_directory_uri() . '/css/layout.css' );
}
add_action( 'wp_enqueue_scripts', 'load_child_stylesheet' );
Run Code Online (Sandbox Code Playgroud)

您可以参考这篇文章,其中讨论了类似的问题

  • 同意@WisdmLabs。注意get_template_directory_uri返回父主题目录,get_stylesheet_directory_uri返回子主题目录 (2认同)