Skip to content

Instantly share code, notes, and snippets.

@nathan-roberts
Last active May 19, 2022 03:40
Show Gist options
  • Save nathan-roberts/145cf4f47f5faffb6bab6044875e3c70 to your computer and use it in GitHub Desktop.
Save nathan-roberts/145cf4f47f5faffb6bab6044875e3c70 to your computer and use it in GitHub Desktop.
Remove Core Gutenberg Blocks
<?php
// Disable core WordPress Gutenberg Blocks
add_filter('allowed_block_types', 'misha_allowed_block_types');
function misha_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;
}
}
return $allowed_blocks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment