$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - How to add custom style to Gutenberg?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - How to add custom style to Gutenberg?

matteradmin11PV0评论

In my Classic Editor, I have loaded a few custom styles, which can be selected from an additional "Format" dropdown list. They are included into an editor-style.css.

Now, in Gutenberg, that dropdown is no more visible and I can't apply my custom styles to the text.

How can I add custom styles to Gutenberg editor?

In my Classic Editor, I have loaded a few custom styles, which can be selected from an additional "Format" dropdown list. They are included into an editor-style.css.

Now, in Gutenberg, that dropdown is no more visible and I can't apply my custom styles to the text.

How can I add custom styles to Gutenberg editor?

Share Improve this question edited Dec 5, 2018 at 15:14 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Dec 5, 2018 at 9:46 Fabio MarzoccaFabio Marzocca 2134 silver badges14 bronze badges 2
  • Have you checked if your formatting dropdown list is available in the classical editor block? I haven't checked, but I wonder if it grabs the custom code for the classical editor as well. – birgire Commented Dec 5, 2018 at 9:56
  • 1 Yes, it is shown. – Fabio Marzocca Commented Dec 5, 2018 at 10:08
Add a comment  | 

1 Answer 1

Reset to default 2

Editor styles work much differently in the block editor. This is because the content in the previous editor was loaded in an iframe, so you could use a stylesheet isolated from the rest of the admin, and do things like use the body selector to change the font in the editor.

The content in block editor, on the other hand, is not in an iframe, and shares styles with the rest of the admin. So if you tried to load an editor style in the block editor that changed the body font colour, you'd change the font colour for the entire UI.

Thankfully WordPress has a way to enqueue a stylesheet and apply styles as if it were an iframe. All you need to do is register support for editor styles:

add_theme_support( 'editor-styles' );

Then you can continue to enqueue an editor stylesheet like before:

add_editor_style( 'editor-style.css' );

But WordPress will now dynamically modify the CSS rules so that they only apply to the content in the editor. For example, CSS targeting the body element will be changed to target .editor-styles-wrapper.

See the section on editor styles from the Gutenberg handbook for more.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far