Skip to content

Instantly share code, notes, and snippets.

@nathan-roberts
Last active May 19, 2022 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathan-roberts/39879fda12ae41156f544569cb51e024 to your computer and use it in GitHub Desktop.
Save nathan-roberts/39879fda12ae41156f544569cb51e024 to your computer and use it in GitHub Desktop.
Disable Core Gutenberg Blocks
add_filter('allowed_block_types', 'ca_allowed_block_types');
function ca_allowed_block_types($allowed_blocks)
{
$allowed_blocks = [];
$block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
$blocks = array_keys($block_types);
foreach ($blocks as $block => $block_name) {
if (strpos($block_name, 'core') !== 0) {
$allowed_blocks[] = $block_name;
}
// leave this block in as taking it out removes some editor formatting
if ($block_name == 'core/paragraph') {
$allowed_blocks[] = $block_name;
}
}
// var_dump($allowed_blocks);
// die();
return $allowed_blocks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment