Wordpress 如何在子主题中编辑layout.css
我在儿童主题里面工作。 我的Wordpress 如何在子主题中编辑layout.css,wordpress,themes,parent-child,Wordpress,Themes,Parent Child,我在儿童主题里面工作。 我的style.css文件在子主题中工作正常,但我的layout.css文件在子主题中不工作 父主题中layout.css的目录结构是mytheme/css/layout.css 我在子主题中保持了相同的目录结构,即mychildtheme/css/layout.css 但是当我在childlayout.css中编写代码时,它不起作用 浏览器从父主题中选取代码(layout.css) 请让我知道我必须做些什么,以便子主题中的layout.css能够正常工作。样式表与常规主
style.css
文件在子主题中工作正常,但我的layout.css
文件在子主题中不工作
父主题中layout.css
的目录结构是mytheme/css/layout.css
我在子主题中保持了相同的目录结构,即mychildtheme/css/layout.css
但是当我在childlayout.css
中编写代码时,它不起作用
浏览器从父主题中选取代码(layout.css
)
请让我知道我必须做些什么,以便子主题中的
layout.css
能够正常工作。样式表与常规主题php文件不同。有了这样一个php文件,在主题中创建一个同名文件就足够了,WP将知道如何使用它。然而,在css中,仅仅创建一个同名文件是不够的。您必须明确地将其包含到您想要的页面中
最好的方法是使用子主题的function.php
文件中的函数。以下是根据您描述的目录结构执行此操作的方法:
<?php wp_enqueue_style( 'child-theme-layout', get_stylesheet_directory_uri().'/css/layout.css' ); ?>
您需要在子主题中包含layout.css文件。 有关更多详细信息,您可以在此处查看:
最好的解决方案是确保在父主题的layout.css之后加载子主题的style.css。然后,您可以通过style.css以通常的方式轻松覆盖所需的小内容 下面是一些适用于WooThemes产品的代码,它确保您的子主题css总是在父-子主题的layout.css之后加载 它属于子主题的functions.php
function use_parent_theme_stylesheet() {
// Use the parent theme's stylesheet
return get_template_directory_uri() . '/style.css';
}
function my_theme_styles() {
$themeVersion = wp_get_theme()->get('Version');
// Enqueue our style.css with our own version
wp_enqueue_style('child-theme-style', get_stylesheet_directory_uri() . '/style.css',
array('woo-layout'), $themeVersion);
}
// Filter get_stylesheet_uri() to return the parent theme's stylesheet
add_filter('stylesheet_uri', 'use_parent_theme_stylesheet');
// Enqueue this theme's scripts and styles (after parent theme)
add_action('wp_enqueue_scripts', 'my_theme_styles', 20);
嗨,莉娅·科恩。我将在我的child function.php中编写该函数。请您解释一下“您必须将它显式地包含到您想要的页面中。”因为我在我的child主题中使用了一个style.css。我将把它包括在哪里。ThanksHi@MC3-包含它的方法是使用我的答案中给出的代码