admin管理员组文章数量:1394082
How can I add custom metabox in document tab in gutenberg?
There is documentation about adding plugin sidebar here, but I'm looking for adding custom metabox in existing document tab.
How can I add custom metabox in document tab in gutenberg?
There is documentation about adding plugin sidebar here, but I'm looking for adding custom metabox in existing document tab.
Share Improve this question asked Feb 3, 2019 at 15:38 AnkitAnkit 3543 silver badges10 bronze badges3 Answers
Reset to default 8Here is the solution. Hope it will help you
const { registerPlugin } = wp.plugins; const { PluginDocumentSettingPanel } = wp.editPost; const MyDocumentSettingTest = () => ( <PluginDocumentSettingPanel className="my-document-setting-plugin" title="My Panel"> <p>My Document Setting Panel</p> </PluginDocumentSettingPanel> ); registerPlugin( 'document-setting-test', { render: MyDocumentSettingTest } );
https://github/WordPress/gutenberg/blob/master/packages/edit-post/src/components/sidebar/plugin-document-setting-panel/index.js#L86
I took a look at Richard Tape's article which required you create your own Gutenberg React component (which is likely the best, most customisable way to do it). But I also have Advanced Custom Fields Pro installed (it has to be version 5.8.0-beta3). That provides a much easier method to add a custom meta field to the Gutenberg sidebar.
Create a new field in ACF Pro and in the Field group settings, ensure you have the following settings configured:
- Style: Standard (WP Metabox)
- Position: Side
This has worked for me ( added a Reading time field). Hope this helps.
https://wordpress/gutenberg/handbook/designers-developers/developers/backward-compatibility/meta-box/ and https://developer.wordpress/reference/functions/add_meta_box/
use $context = 'side'
Example:
add_meta_box( 'my-meta-box', 'My Meta Box', 'my_meta_box_callback',
null, 'side', 'high',
array(
'__back_compat_meta_box' => true,
)
);
本文标签: custom fieldAdd metabox to document tab in gutenberg
版权声明:本文标题:custom field - Add metabox to document tab in gutenberg 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744635185a2616782.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论