Skip to content

Instantly share code, notes, and snippets.

@khromov
Created June 9, 2022 23:32
Show Gist options
  • Save khromov/9451c9d5d0d7260fed3ea37535d1ef2b to your computer and use it in GitHub Desktop.
Save khromov/9451c9d5d0d7260fed3ea37535d1ef2b to your computer and use it in GitHub Desktop.
WordPress Gutenberg - Control allowed blocks by post type
<?php
add_filter( 'allowed_block_types_all', function($allowed_block_types, $block_editor_context) {
if ( $block_editor_context->post->post_type === 'post' ) {
return [
'acf/my-cool-block',
'core/paragraph'
];
}
return $allowed_block_types;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment