admin管理员组文章数量:1431521
For example:
Before: <div id="block-fc502ca9-0d7b-440c-959c-3da152db0192" class="wp-block editor-block-list__block" data-type="wordcamp/schedule">
After: <div id="block-fc502ca9-0d7b-440c-959c-3da152db0192" class="wp-block editor-block-list__block" data-type="wordcamp/schedule" data-foo="bar">
For example:
Before: <div id="block-fc502ca9-0d7b-440c-959c-3da152db0192" class="wp-block editor-block-list__block" data-type="wordcamp/schedule">
After: <div id="block-fc502ca9-0d7b-440c-959c-3da152db0192" class="wp-block editor-block-list__block" data-type="wordcamp/schedule" data-foo="bar">
1 Answer
Reset to default 4You can define a getEditWrapperProps
function when you register the block, and return an object that sets the props for the wrapper.
The function will be passed the props for the block, in case those are needed.
registerBlockType( 'wpse/example-get-edit-wrapper-props', {
title : 'getEditWrapperProps() Example',
// ...
getEditWrapperProps( props ) {
return {
'data-foo': 'bar',
'data-quix': props.quix || false,
};
},
} );
That also lets you change any of other other props that get passed to the container, like id
, className
, onClick
, tabIndex
, etc. Obviously, you probably shouldn't mess with those unless you really know what you're doing, and understand the consequences.
Declaration in Gutenberg source: 1, 2.
Examples in Core blocks: 1, 2, 3
本文标签: How can I add arbitrary data attributes to a block39s edit() container
版权声明:本文标题:How can I add arbitrary `data-` attributes to a block's `edit()` container? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745566136a2663771.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论