首页  >  问答  >  正文

Wordpress中的子主题style.css无法覆盖index.php文件

希望能帮到你。 我为我的 WordPress 页面创建了一个子主题,并在其中设置了 style.css 和functions.php。我假设队列已正确设置,因为我可以更改一些不同的内容并且它显示成功。但是,如果我尝试更改 index.php 中的某些内容,它不会覆盖。

例如,我试图更改鼠标悬停在链接上时的颜色。

我已经检查了各种其他帖子和文档,但似乎没有帮助。

如果我的队列实际上是正确的,任何建议或确认将不胜感激。

这是我的 style.css

/* Theme Name:   Blossom pin child
Theme URI:    https://www.diagnosischerry.co.uk
Description:  A blossom pin child theme 
Author:       Blossom Themes
Author URI:   https://blossomthemes.com/
Template:     blossom-pin
Version:      1.0.0
Text Domain:  blossom-pin-child
*/

.archive #primary .post .entry-header .category a {
    background: red!important;
}

.archive #primary .post .entry-header .category a:hover {
    background: red!important;
}

这是我的functions.php

<?php
// enqueue parent styles

function blossompin_scripts() {
    wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
    wp_enqueue_style('child-style', get_stylesheet_uri() . '/style.css');
    }
    add_action('wp_enqueue_scripts', blossompin_scripts);

    
?>

编辑: 排队似乎是正确的,因为我能够更新文本和其他一些文本的背景,但我在精确定位和更改类别链接的背景颜色时遇到问题。

下面是我指的粉色背景

上图为检查时的图片。如果我将顶部的颜色从粉红色更改为红色,它会发生变化,但如果我要复制所有这些并将其放入我的 style.css 中,或者只选取我认为与之相关的部分,那么它不会改变颜色,只是保留粉红色。

非常感谢 雷

P粉103739566P粉103739566179 天前265

全部回复(1)我来回复

  • P粉317679342

    P粉3176793422024-03-28 15:29:04

    您错误地使用了 get_stylesheet_uri() 函数,而不是与 CSS 相关的问题。 如果您检查 get_stylesheet_uri() 函数的定义,您可以看到它返回子主题目录中 style.css 文件的完整 URL

    function get_stylesheet_uri() {
        $stylesheet_dir_uri = get_stylesheet_directory_uri();
        $stylesheet_uri     = $stylesheet_dir_uri . '/style.css';
        return apply_filters( 'stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri );
    }

    因此,要将 style.css 放入子主题中,您应该使用 wp_enqueue_style('child-style', get_stylesheet_uri());wp_enqueue_style('child-style', get_stylesheet_directory_uri( ) .'/style.css');

    回复
    0
  • 取消回复