WordPress开发-“编辑器样式”问题

时间:2019-05-06 12:42:04

标签: php wordpress themes

我正在创建WordPress主题。但是我面临一个有趣的问题。因此,我在编辑器样式中添加了Google字体。并且它可以在本地主机上正常工作。 Bu在真正的主机上不起作用。哪里有问题? 我的代码:

  # Editor Style support #
  add_theme_support( 'editor-styles' );
  # editor assets #
  add_editor_style(get_template_directory_uri() .'/style-editor.css');
  add_editor_style('https://fonts.googleapis.com/css?family=Poppins:400,500,700');
  add_editor_style('assets/css/font-awesome-4.css');

1 个答案:

答案 0 :(得分:0)

更新后:请尝试从Wordpress开发人员文档中进行尝试:https://developer.wordpress.org/reference/functions/add_editor_style/

使用Google字体

Google Fonts API为CSS文件提供了一个URL,该URL可以包含多种类型的面孔,并以逗号分隔。必须先对URL中的逗号进行编码,然后才能将字符串传递给add_editor_style。

/**
 * Registers an editor stylesheet for the current theme.
 */
function wpdocs_theme_add_editor_styles() {
    $font_url = str_replace( ',', '%2C', '//fonts.googleapis.com/css?family=Lato:300,400,700' );
    add_editor_style( $font_url );
}
add_action( 'after_setup_theme', 'wpdocs_theme_add_editor_styles' );