首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress子主题style.css不工作

Wordpress子主题style.css不工作
EN

Stack Overflow用户
提问于 2016-10-11 10:43:16
回答 8查看 53.5K关注 0票数 22

我已经创建了与父主题相同格式的文件结构。我的父主题名为阿尔卑斯,在阿尔卑斯内有一个functions.php和style.css文件。似乎没有任何其他的style.css文件。

我创建了一个名为Alpine的目录,并在其中创建了一个functions.php和style.css文件。

我不知道为什么我对子style.css所做的任何更改都没有实现,但当我在父style.css中进行相同的更改时,它们就实现了。

这是我的孩子style.css:

代码语言:javascript
复制
/*
 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
*/

这是我的子functions.php文件:

代码语言:javascript
复制
<?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' );
}
?>

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2016-10-11 16:28:16

看看你的<head>标签。更重要的是,看看样式表的顺序。

首先添加来自子主题的样式,然后添加父主题中的所有样式。这将导致父主题的样式覆盖子主题样式。

通过使用my_theme_enqueue_styles的第三个参数,您可以将my_theme_enqueue_styles函数的优先级更改为在父函数之后运行。这将使您的子主题样式队列持续,并允许CSS按预期工作。

代码语言:javascript
复制
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 11 );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'child-style', get_stylesheet_uri() );
}
?>
票数 44
EN

Stack Overflow用户

发布于 2018-03-21 22:21:13

这对我起了作用:

代码语言:javascript
复制
<?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() );
}
?>

其他的答案都没有。

票数 20
EN

Stack Overflow用户

发布于 2021-09-30 11:35:18

从Divi4.4.1更新到Divi4.10.8之后,子主题父CSS无法工作。我在我的网站上做了一些研究,发现Divi style.css文件是空的,只有头信息(更新后),显示CSS的代码现在在一个不同的文件( style-static.min.css )中,我把我的子主题functions.php文件中的文件名从style.css更改为style-static.min.css。这解决了我的问题,CSS正在工作。

在我使用的代码下面看:

代码语言:javascript
复制
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 11);
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style-static.min.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array('parent-style')
    );
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39975520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档