设置古腾堡编辑器默认字体

古腾堡编辑器(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 条评论

发表回复

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