apply_filters( 'allowed_block_types', bool|array $allowed_block_types , WP_Post $post )
Filters the allowed block types for the editor, defaulting to true (all block types supported).
Parameters Parameters
- $allowed_block_types
-
(bool|array) Array of block type slugs, or boolean to enable/disable all.
- $post
-
(WP_Post) The post resource data.
Source Source
Changelog Changelog
Version | Description |
---|---|
5.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
This allows only paragraph block for post.
When filtering for allowed block types, return the boolean for the post types you are not restricting. Otherwise, it won’t work as Nilambar’s example because
$allowed_block_types
is expecting an array or a boolean.This worked for me when filtering allowed blocks for a custom post type. You’ll want to substitute ‘myplugin’ with your namespace and the post types you’re filtering in the switch statement.
Expand full source codeCollapse full source code
Feedback
I would recommend to use Nilambar Sharma’s example rather than this one. First of all this example is expecting that no one else has already used this hook. If non of the cases is true, this example will set
$allowed_block_types
to true no matter if someone else has used this hook to allow or forbid block-types for any other post-types. Returning the current value of$allowed_block_types
is the better option because when no one has ever used this hook,$allowed_block_types
will be true by default. If someone has used it$allowed_block_types
will be true, false or an array. Second of all the return statement in line 14 is unreachable and therefore unnecessary. — By devper —It would appear that as of WordPress 5.6 the
core-embed/*
blocks have all been replaced with Variations so this functionality now no longer works for all the various Embed “blocks”.