在Gutenberg编辑器中添加自定义字体(我的网站的字体)

问题描述 投票:2回答:1

我想将gutenberg编辑器改编成我网站的外观,并将我的web字体用于各种块元素。我一直在寻找插件的各种文件夹/ CSS文件,但没有找到任何有用的东西。编辑器的字体定义在哪里?

谢谢你们!

大卫

wordpress webfonts wordpress-gutenberg
1个回答
2
投票

我不知道是否有正式方法,但你可以为此创建一个小插件(Gutenberg块编辑器资产,没有块,准确)。

  1. 在/ wp-content / plugins中创建一个名为gutenbergfontchanger(或更好名称)的文件夹
  2. 添加一个名为gutenbergfontchanger.php的PHP文件,其代码与此类似:
<?php
/*
Plugin Name: gutenbergfontchanger
*/

if (!function_exists('gutenbergfontchanger_editor_assets')) {
    function gutenbergfontchanger_editor_assets()
    {
        wp_enqueue_style(
            'gutenbergfontchanger-editor-style',
            plugins_url('editor.css', __FILE__),
            filemtime(plugin_dir_path(__FILE__) . 'editor.css')
        );
    }

    add_action('enqueue_block_editor_assets', 'gutenbergfontchanger_editor_assets');
}
  1. 添加一个名为editor.css的CSS文件,其中包含您的字体样式:
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,600');

.editor-styles-wrapper, .editor-post-title__input {
  font-family: 'Source Sans Pro', sans-serif !important;
}
  1. 激活WordPress后端内的插件。
© www.soinside.com 2019 - 2024. All rights reserved.