Warning: This hook has been deprecated. Use the ‘allowed_block_types_all’ filter instead.

apply_filters_deprecated( 'allowed_block_types', bool|array $allowed_block_types, WP_Post $post )

Filters the allowed block types for the editor.


Parameters Parameters

$allowed_block_types

(bool|array) Array of block type slugs, or boolean to enable/disable all. Default true (all registered block types supported)

$post

(WP_Post) The post resource data.


Top ↑

Source Source

File: wp-includes/block-editor.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
5.8.0 Use the 'allowed_block_types_all' filter instead.
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by Katrina Yancey

    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.

    function myplugin_allowed_block_types( $allowed_block_types, $post ) {
    	
    	switch( $post->post_type ) {
            case 'my_cpt_1':
                return array( 'core/paragraph' );
                break;
            case 'my_cpt_2':
                return array( 'core/paragraph', 'core/heading' );
                break;
            default:
                return true;
        }
    
        return $allowed_block_types;
    
    }
    add_filter( 'allowed_block_types', 'myplugin_allowed_block_types', 10, 2 );
    
    
    

  2. Skip to note 3 content
    Contributed by Nilambar Sharma

    This allows only paragraph block for post.

    
    function wpdocs_allowed_block_types( $allowed_block_types, $post ) {
        if ( $post->post_type !== 'post' ) {
            return $allowed_block_types;
        }
    
        return array( 'core/paragraph' );
    }
    
    add_filter( 'allowed_block_types', 'wpdocs_allowed_block_types', 10, 2 );
    

You must log in before being able to contribute a note or feedback.