php - Unable to change the WordPress tinymce editor font
问题描述
I'm currently trying to change the WordPress tinymce editor font but it's not working.
First I've created a tinymce-custom-editor.css
with the following content:
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
* {
font-family: "Open Sans", Arial, sans-serif !important;
}
After saving and uploading I've included it in my themes functions.php
file this way:
/**
* Add editor styles
*/
add_action( 'after_setup_theme', 'add_custom_editor_style' );
function add_custom_editor_style() {
add_editor_style( get_stylesheet_directory_uri() . '/css/tinymce-custom-editor.css' );
}
I'm getting no error that the file can't be found so I expect that it's getting included successfully. When I delete the cache and reload the page, the font is still the wrong one:
font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
It must looks like this here:
What I'm doing wrong here?
解决方案
首先,您应该确保css
资源已加载(在页面源中查找)。如果已加载,则说明您走在正确的道路上。如果不是,请找出 WP 试图从哪里加载它并更正路径。
你的第二个问题是你的*
选择器太笼统了(它会影响所有还没有 set 的东西font-family
)而且太弱(它会被几乎任何其他选择器覆盖font-family
到任何元素)。
因此,如果样式表加载正确,您所要做的就是应用font-family
到尚未设置它的任何元素。
您需要检查您尝试设置样式的元素并找到当前应用该font-family
属性的选择器的特殊性。一旦您的选择器比应用的选择器强,您font-family
将应用(如果您的样式表稍后加载,则特异性可以相同并且您的值仍然适用)。
推荐阅读
- google-photos - 我如何在 mediaItems 搜索 api 上搜索上传到 Google 照片时的图像(不是在创建时)
- mysql - 在当前表上插入后,Mysql触发器更新其他表
- javascript - 如何将项目添加到 JSON 对象
- javascript - jQuery 根据其他元素的类隐藏或显示元素
- diameter-protocol - 使用 seagull 多次发送 Diameter 消息
- html - 带有可扩展子元素的 flexbox
- php - Access-Control-Allow-Origin'标头在角度 laravel 应用程序上存在错误
- import - 可以使用infile在sas程序中导入sas日志文件吗(以批处理模式执行,即PuTTY)?
- php - 没有获得 $_POST 数据 (PHP 7.1/Debian 8) LAMP 问题
- java - 如何将 AIResponse gson 转换为可用于 Text to Speech 的文本?