限制古腾堡块只能使用

时间:2019-06-25 21:03:19

标签: wordpress-gutenberg

我的块已正确注册并可以正常运行。我唯一的警告是,我不希望在同一篇文章中使用这些块超过1(一次)时间。是否可以限制这样的块行为?文档太可怕了。

预先感谢

2 个答案:

答案 0 :(得分:0)

如果您要注册自己的块,则可以在注册块时将multiple supports选项设置为false,请参阅此处的官方文档:https://developer.wordpress.org/block-editor/developers/block-api/block-registration/#supports-optional

答案 1 :(得分:0)

对于也需要此功能的任何人,以下是您如何限制块仅供一次性使用:

// A Sample Block
acf_register_block(array(
    'name'              => 'blockname',
    'title'             => __('Block Name','slug'),
    'description'       => __('A translatable description','slug'),
    'render_callback'   => 'theme_block_render',
    'category'          => 'embed', //the block category (optional)
    'align'             =>  'wide', // default value for width
    'mode'              => 'auto', // default value for switching auomatically between edit and view mode
    'supports'          => array('align' => array('wide','full' ),'multiple' => false), // wide and full are optional, those are for setting the width. SET MULTIPLE TO FALSE HERE!
    'icon'              => 'welcome-view-site', // Use a dashicon, for example dashicons-welcome-view-site
    'keywords'          => array( 'blockname', 'image','text' ), //set some keywords for search
)); 

可在此处找到更多文档:https://www.advancedcustomfields.com/resources/acf_register_block_type/