Wordpress 子主题 style.css 不起作用 [英] Wordpress child theme style.css not working

查看:35
本文介绍了Wordpress 子主题 style.css 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个与父主题格式相同的文件结构.我的父主题称为 Alpine,在 Alpine 中有一个 functions.php 和 style.css 文件.似乎没有任何额外的 style.css 文件.

I have created a file structure in the same format as my parent theme. My parent theme is called Alpine and within Alpine there is a functions.php and style.css file. There do not appear to be any additional style.css files.

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

I have created a directory called Alpine-child and within that I have created a functions.php and style.css file.

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

I can't work out why any changes I make to the child style.css are not implemented but they are when I make the same changes in parent style.css

这是我的孩子 style.css:

This is my child 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
*/

这是我的子functions.php文件:

This is my child functions.php file:

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

推荐答案

看看你的 标签.更重要的是查看样式表的顺序.

Take a look at your <head> tag. More importantly look at the order of your stylesheets.

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

The styles from your child theme are being added first and then all the styles from your parent theme. This will cause the styles from the parent theme to override your child theme styles.

您可以使用 add_action.这将使您的子主题样式最后排入队列,并允许 CSS 按预期工作.

You can change the priority of your my_theme_enqueue_styles function to run after the parent by using the third parameter of add_action. This will enqueue your child theme styles last and allow the CSS to work as expected.

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 11 );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'child-style', get_stylesheet_uri() );
}
?>

这篇关于Wordpress 子主题 style.css 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆