Skip to content

Instantly share code, notes, and snippets.

@Christian-Roth
Last active February 11, 2022 09:05
Show Gist options
  • Save Christian-Roth/a5c3ffe98181bd8671fc10f1dd5fb1bb to your computer and use it in GitHub Desktop.
Save Christian-Roth/a5c3ffe98181bd8671fc10f1dd5fb1bb to your computer and use it in GitHub Desktop.
Remove all blocks from the theme category. Useful if you use the WP Block Editor but not a Full Site Editing Theme.
<?php /* Remove all blocks from the theme category */
function custom_allowed_block_types ( $allowed_block_types, $block_editor_context ) {
$block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
if (!empty($block_types)) {
$allowed_block_types = array();
foreach ($block_types as $key => $value) {
if ($value->category != 'theme') {
$allowed_block_types[] = $key;
}
}
}
return $allowed_block_types;
}
add_filter( 'allowed_block_types_all', 'custom_allowed_block_types', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment