Skip to content

Instantly share code, notes, and snippets.

@robertannett
Created May 31, 2021 14:52
Show Gist options
  • Save robertannett/8fe04e17d284791692cb5e03420f3f29 to your computer and use it in GitHub Desktop.
Save robertannett/8fe04e17d284791692cb5e03420f3f29 to your computer and use it in GitHub Desktop.
Wordpress - Disable Gutenberg blocks / Whitelist Blocks
/*
** Reference: https://rudrastyh.com/gutenberg/remove-default-blocks.html
*/
add_filter( 'allowed_block_types', 'custom_allowed_block_types', 10, 2 );
function custom_allowed_block_types( $allowed_blocks, $post ) {
$allowed_blocks = array(
'core/paragraph',
'core/image',
'core/heading',
'acf/custom-block-one',
'acf/custom-block-two',
'acf/custom-block-three'
);
if( $post->post_type === 'page' ) {
$allowed_blocks[] = 'core/shortcode';
}
return $allowed_blocks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment