I have a post type that requires a custom block. The post type supports all other blocks, but the block supports only this post type.
What I’d like:
- Allow this block to be inserted and edited when editing this post type.
- Do not allow this block to be inserted and edited when editing another post type.
- Render this block on any view it is… uh, rendered.
I can’t use the
allowed_block_types_all filter. This is only useful when you have a small, predefined list of blocks you’d like to allow. The default value is
true, meaning all. There is no way to remove a single block type.
There are very long discussions on GitHub that start to cover possible future solutions for this, but no clear answer yet.
What I’ve found:
- Allow/deny block use based on post-type or template context
- A brief note on Introduce Child Blocks
- Limit Block to Certain Post Type(s)
- Adding option in registerBlockType function to specify post_types to restrict a block from appearing everywhere
The cleanest, if somewhat hacky feeling, answer I have so far is: