php - Wordpress 子主题 style.css 不工作

标签 php wordpress

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

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

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

这是我的 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 文件:

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

最佳答案

看看你的<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() );
}
?>

关于php - Wordpress 子主题 style.css 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39975520/

相关文章:

php - 从发布的数据创建对象实例 - PHP

php - 获取数据库信息的更好方法

javascript - 如何将ajax集成到Wordpress主题中?

javascript - 如何在短代码中使用 javascript 变量?

php - 根据 Woocommerce 产品循环中的日期时间规则显示下一个交货日

wordpress - 使子域也受到保护 https ://

php - 使用 SWIG 在 PHP 中迭代 std::map

php - 如何仅使用非空用户输入字段更新 MySQL 数据库

php 声称我定义的变量未定义

javascript - 我如何编辑这个以在鼠标输入时展开并在鼠标离开时折叠