古腾堡编辑器(Gutenberg Editor)发展了五年,如今早已是WordPress默认的编辑器。

在2020年文《更改古腾堡编辑器默认字体》中,提到如何更改编辑器的默认字体以实现实时预览文章效果。如今有相对更优雅的方法来实现。

1、在根目录建css文件夹,添加editor.css文件

/* Start font set for Gutenberg */
@import url('../css/wenkai.css');

.editor-post-title__block .editor-post-title__input, .block-editor-block-list__layout, .editor-rich-text.block-editor-rich-text, .wp-block-paragraph, .editor-styles-wrapper {
	font-family: "LXGW WenKai Screen", sans-serif !important;
}

.editor-post-title__block .editor-post-title__input {
/*	font-size: 42px;
	font-weight: 400;
	line-height: 50px;
	text-align: center;
*/
}

.edit-post-visual-editor, .edit-post-visual-editor p,
.editor-rich-text__tinymce.mce-content-body {
/*	font-size: 20px;
	line-height: 30px;
*/
}
/* End of font set for Gutenberg */

2、在function.php中添加

// Gutenberg default font
function guten_block_editor_assets() {
wp_enqueue_style(
'guten-editor-style',
get_stylesheet_directory_uri() . "/css/editor-style.css",
array(),
'1.0'
);
}
add_action('enqueue_block_editor_assets', 'guten_block_editor_assets');

共有 14 条评论

  1. 子痕

    江苏

    这要求是得多高还想要改编辑器的字体啊。

    一年前 Microsoft Edge 109 · Windows 10

    回复

    • S

      江苏

      @子痕 哈哈,改改更舒坦

      一年前 Microsoft Edge 109 · Windows 10

      回复

  2. Jack

    上海

    还是喜欢 markdown,刚玩博客的时候真是难受了好久呀

    一年前 Safari 16 · iPhone iOS 16.1

    回复

    • S

      江苏

      @Jack 其实古腾堡集成了markdown,比如我写井号带字:
      ### 这个
      在古腾堡里就是标题。

      一年前 Microsoft Edge 109 · Windows 10

      回复

  3. 櫻川 浅羽

    奥地利

    我還挺喜歡編輯器的預設字型和排版的,甚至想直接用作佈景主題😂

    一年前 Firefox 102 · Windows 10

    回复

  4. 不亦乐乎

    福建

    我来测试一下,好像你这边也不会记住,双击输入框会有下拉。

    一年前 Google Chrome 110 · Windows 10

    回复

    • S

      江苏

      @不亦乐乎 我刚测了,可以记住啊。

      一年前 Wordpress App 21 · iPhone iOS 16.2

      回复

      • 不亦乐乎

        福建

        @S 难道和我的一样,是自己的浏览器本地的cookie长期存着,没有强制刷掉?

        一年前 Google Chrome 110 · Windows 10

        回复

        • S

          江苏

          @不亦乐乎 不会的,我换了三台设备、四个浏览器了。

          一年前 Microsoft Edge 109 · Windows 10

          回复

          • 不亦乐乎

            福建

            @S 大发的主题应该不会出这种问题,估计是我这边问题。

            一年前 Epiphany 605 · Ubuntu

            回复

            • S

              江苏

              @不亦乐乎 我也是他的主题改的。
              需要自己添加记住cookie的js。

              一年前 Safari 16 · Mac OS X 10.15

              回复

  5. 拾风

    广东

    编辑器的字体都要倒腾,看来开年的工作任务不多,气氛比较融洽,心情比较愉悦,哈哈。

    一年前 Safari 16 · iPhone iOS 16.3

    回复

    • S

      江苏

      @拾风 并没有,压力还挺大的。纯粹是自娱自乐,缓解压力。

      一年前 Microsoft Edge 109 · Windows 10

      回复

       

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注