尝试覆盖/附加子主题中父主题的editor-style.css

时间:2019-05-27 16:56:22

标签: php wordpress wordpress-gutenberg

我将二十一岁的孩子用于简单的工作,并使用孩子覆盖样式。

问题是,当我在子主题文件夹中添加editor-child.css时,编辑器样式不会被覆盖。 在子主题functions.php中添加add_editor_style(包装在after_setup_theme中)似乎不起作用。我不能加载多种编辑器样式吗,或者这是什么问题?我不知道如何覆盖古腾堡的这个丑陋的二十一个编辑器css。禁用它甚至可能更好,但是即使使用remove_editor_style也不起作用。而且我无法使用google或stackoverflow找到关于该主题的任何信息。

<?php
// In the child theme functions.php. I simply want to use the style.css by the child theme as an extra editor style
function wysiwyg_styles() {
    add_editor_style( get_stylesheet_uri() );
}
add_action( 'after_setup_theme', 'wysiwyg_styles');
?>

管理员中未加载任何CSS(删除了chache和cookie后)

2 个答案:

答案 0 :(得分:0)

发生的情况是您使用了错误的动作挂钩……您应该使用 admin_enqueue_scripts 挂钩。

尝试这样操作。然后检查它是否对您有用:

add_action('admin_enqueue_scripts', function () {
  wp_enqueue_style('admin-styles', get_stylesheet_directory_uri().'/pathToYour.css');
});

// If the above does not work change get_stylesheet_directory_uri() for get_template_directory_uri()

希望这会有所帮助,祝你好运。

答案 1 :(得分:0)

您可以尝试:

add_theme_support( 'editor-styles' );
add_editor_style( 'style-editor.css' );

在您的 functions.php 中。尚未检查它是否适合儿童主题。

更多信息在这里: https://developer.wordpress.org/block-editor/developers/themes/theme-support/