【问题标题】:Wordpress child theme style.css has stopped workingWordpress 子主题 style.css 已停止工作
【发布时间】:2019-03-05 20:16:03
【问题描述】:

真的希望有人可以帮助我!我刚刚在我的 Wordpress 网站 (www.ellymacdonalddesign.com) 上更新了 Divi 父主题,而子 CSS 主题似乎已经停止工作。

我已经尝试了这个问题的解决方案,但它们似乎对我不起作用: Wordpress child theme style.css not working

我的子functions.php文件目前是:

<?php
function my_theme_enqueue_styles() {
    $parent_style = 'divi-style'; 
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( $child-style, get_stylesheet_uri() );
}
?>

非常感谢任何指导,在此先感谢您, 艾莉

【问题讨论】:

  • 我看到了这个函数,但你没有在任何地方调用它。您在该函数之前或之后是否有add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
  • 非常感谢您的回复。不,我真的不知道我在用 functions.php 代码做什么(我已经自学了 stylesheet.css 代码,但还没有机会学习 .php 的东西)——应该这样吗?:
  • 是的。您应该只添加我在您的函数上方直接发布的行。那应该可以。
  • 嗨 - 感谢您的帮助,非常感谢。我已将该代码添加到 functions.php 文件中,但子主题仍然无法正常工作。所以我想肯定还有其他问题。我想我可能会尝试删除 Child 主题然后恢复它,希望这可能会奏效。再次感谢您。

标签: php css wordpress


【解决方案1】:

你的变量$child-style有什么价值吗?根据document,需要句柄名称(第一个参数)。这就是为什么您的子主题仍然无法正常工作的原因。

试试下面的代码看看是否有效:

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    $parent_style = 'divi-style'; 
    $child_style = 'divi-style-child'; 
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( $child_style, get_stylesheet_uri() );
}

【讨论】:

    【解决方案2】:

    更改 css 子主题版本号有助于解决我网站上的问题。

    在我决定从 Wordpress 的“主题编辑器”界面更改 style.css 文件中的一些 css 规则之前,我的子主题一直正常工作。我注意到网站上没有出现任何更改,尽管 css 显然已加载到标题中并且我也清除了所有缓存。
    我尝试了以下问题的解决方案,但我认为这是用于新的子主题安装,而不是已经工作的:Wordpress child theme style.css not working

    我决定更改我的子主题的版本号,修改后终于考虑到了。

    /*
     Theme Name:   Chromatic-child
     Template:     chromatic
     Version:      1.1.0
    */
    

    【讨论】:

      猜你喜欢
      • 2017-02-19
      • 2020-09-13
      • 1970-01-01
      • 2022-11-05
      • 2021-01-16
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多