我创建了一个与父主题格式相同的文件结构.我的父主题叫做Alpine,在Alpine里面有一个functions.php和style.css文件.似乎没有任何其他style.css文件.
我创建了一个名为Alpine-child的目录,并在其中创建了一个functions.php和style.css文件.
我无法理解为什么我对子style.css所做的任何更改都没有实现,但是当我在父style.css中进行相同的更改时
这是我的孩子style.css:
/*
Theme Name: Alpine Child
Theme URI: http://www.creative-ispiration.com/wp/alpine/
Description: My first child theme, based on Alpine
Author: MilkshakeThemes
Author URI: http://themeforest.net/user/milkshakethemes
Template: Alpine
Version: 1.0.0
Tags: one-column, two-columns, right-sidebar, fluid-layout, custom-menu, editor-style, featured-images, post-formats, rtl$
Text Domain: alpine-child
*/Run Code Online (Sandbox Code Playgroud)
这是我的孩子的functions.php文件:
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
?>Run Code Online (Sandbox Code Playgroud)
Jro*_*rod 16
看看你的<head>标签.更重要的是,请查看样式表的顺序.
首先添加子主题中的样式,然后添加父主题中的所有样式.这将导致父主题中的样式覆盖您的子主题样式.
您可以my_theme_enqueue_styles使用add_action的第三个参数更改函数在父项后运行的优先级.这将最后将您的子主题样式排入队列,并允许CSS按预期工作.
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 11 );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'child-style', get_stylesheet_uri() );
}
?>
Run Code Online (Sandbox Code Playgroud)
Cra*_*cks 13
这对我有用:
<?php
function my_theme_enqueue_styles() {
$parent_style = 'twentyseventeen-style';
$child_style = 'twentyseventeen-child-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( $child_style, get_stylesheet_uri() );
}
?>
Run Code Online (Sandbox Code Playgroud)
其他答案都没有。
| 归档时间: |
|
| 查看次数: |
22890 次 |
| 最近记录: |