admin管理员组文章数量:1301611
When you add a meta box to Gutenberg, it looks different than the other items in the editor. There is a HR, and the fonts are different.
Does anyone know how to fix this so it looks like a natural part of the site, and not "some junk Automattic didn't add".
Example code:
function myMetaBox() {
add_meta_box(
'MyMetaBox',
"Why the odd font?",
'myBoxOutputCallback',
'post',
'side'
);
}
add_action( 'add_meta_boxes', 'myMetaBox' );
function myBoxOutputCallback(){
echo ("Gutenberg is a great addition! NOT!");
}
When you add a meta box to Gutenberg, it looks different than the other items in the editor. There is a HR, and the fonts are different.
Does anyone know how to fix this so it looks like a natural part of the site, and not "some junk Automattic didn't add".
Example code:
function myMetaBox() {
add_meta_box(
'MyMetaBox',
"Why the odd font?",
'myBoxOutputCallback',
'post',
'side'
);
}
add_action( 'add_meta_boxes', 'myMetaBox' );
function myBoxOutputCallback(){
echo ("Gutenberg is a great addition! NOT!");
}
Share
Improve this question
edited Nov 7, 2019 at 1:19
John Dee
asked Nov 7, 2019 at 1:03
John DeeJohn Dee
5135 silver badges14 bronze badges
0
2 Answers
Reset to default 1Bottom border (HR) can be removed using CSS:
#__BLOCK_ID__.postbox:not(.closed) .postbox-header{
border-bottom: none;
}
p.s. change __BLOCK_ID__
to first parameter used in add_meta_box()
function.
In your example, Discussion is not a meta box. Meta boxes are not a native part of the block editor, and are only supported for backwards compatibility. They are not the correct modern way to add these settings boxes to the block editor. This is why they have different styles.
In the block editor, these sections are "Panels", that fit inside a "Sidebar", and are React components, like the rest of the block editor.
A full guide on creating these is beyond the scope of a single answer on this site, but essentially you need to:
- Use
register_meta()
to register the fields that your panel will be working with. - Creating a React component to manage the custom fields. Some documentation for this is available in the guide for creating a custom sidebar in the editor, which starts here, and CSS-Tricks has a useful article covering this in more detail here.
- If you want to add your panel to the existing "Document" sidebar, and not a custom sidebar, you'll need to use a SlotFill, specifically
PluginDocumentSettingPanel
, to output your component as a panel in the existing sidebar (SlotFills are a bit like hooks, and allow you to add components to sections of the editor).
You can continue to use meta boxes, but they will not visually match the native components that are the new correct way to add fields to the editor.
It's also worth considering whether or not the field you intend to add would work better as a regular block anyway. The documentation for creating those is available here.
本文标签: block editorStyle Gutenberg metaboxes like they belong on the site
版权声明:本文标题:block editor - Style Gutenberg metaboxes like they belong on the site 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741674048a2391775.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论