wordpress - 在后端删除 Gutenberg 编辑器的嵌入式样式表
问题描述
Gutenberg 编辑器带有一个嵌入式样式表。这是该样式表的一个片段:
...
.editor-styles-wrapper {
font-family: "Noto Serif", serif;
font-size: 16px;
line-height: 1.8;
color: #191e23;
}
.editor-styles-wrapper p {
font-size: 16px;
line-height: 1.8;
}
...
我使用以下内容将自己的编辑器样式表排入队列:
add_action("enqueue_block_editor_assets", "enqueue_custom_block_editor_assets");
function enqueue_custom_block_editor_assets() {
wp_enqueue_style("editor-style", get_stylesheet_directory_uri()."/editor-style.css", null, null);
}
由于我有自己的编辑器 stylehseet,我想摆脱默认的。对这个主题的搜索会产生很多删除前端默认块样式的结果,但我指的是后端的编辑器样式。谢谢你的帮助!
解决方案
我深入研究了它是如何被注入的,并找到了一种通过block_editor_settings
过滤器将其消灭的方法。有一个styles
包含 css 的数组的键。对我来说唯一不确定的是我假设数组的形状总是相同的,我应该在这里做一些检查。
add_filter( 'block_editor_settings' , 'remove_guten_wrapper_styles' );
public function remove_guten_wrapper_styles( $settings ) {
unset($settings['styles'][0]);
return $settings;
}
推荐阅读
- hyperledger-fabric - Hyperledger Fabric:向对等方发送提案时超时
- authentication - 服务器如何验证基于会话的 cookie 是真实的?
- sql - 如何使用内部连接更新行
- c - 为什么我的 if 没有捕捉到这个空指针取消引用?
- javascript - 无法选择多选项目。jQuery
- reactjs - 我如何测试函数(getPermissions)并在未涵盖分支和语句的情况下做出反应
- mongodb-query - 模糊的 mongoDB 查询,匹配所有内容
- python - 如何使用 selenium 获取从 python 上的 facebook 联系人收到的最新消息?
- javascript - 如何使用 React Native 获得良好的本地时间?
- reactjs - 反应钩子:记住我登录表单中的复选框不起作用