# Allowed Blocks per Post Type

> Limits the blocks that can be inserted for specific post types, so structured content such as testimonials or team members only uses the blocks that fit.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: blocks, post-types, editor
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/allowed-blocks-per-post-type/

## Code

```php
// Post type => block names allowed in its editor.
$wpide_allowed_blocks_by_type = array(
    'testimonial' => array( 'core/paragraph', 'core/quote', 'core/image' ),
);

add_filter( 'allowed_block_types_all', function ( $allowed, $context ) use ( $wpide_allowed_blocks_by_type ) {
    if ( empty( $context->post ) || ! isset( $wpide_allowed_blocks_by_type[ $context->post->post_type ] ) ) {
        return $allowed;
    }

    return $wpide_allowed_blocks_by_type[ $context->post->post_type ];
}, 10, 2 );
```

## Notes

Post types that are not listed keep every block. Blocks already in a post keep working.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Allowed Blocks per Post Type" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
