Skip to content

Instantly share code, notes, and snippets.

@rocket-martue
Created December 5, 2021 13:37
Show Gist options
  • Save rocket-martue/35a2fb7aa819450d4d828bb6bb50a70d to your computer and use it in GitHub Desktop.
Save rocket-martue/35a2fb7aa819450d4d828bb6bb50a70d to your computer and use it in GitHub Desktop.
JavaScriptで必要なブロックのみ表示する (ホワイトリスト形式)
wp.domReady( () => {
const registerBlocks = [
'core/paragraph',
'core/heading',
'core/list',
'core/embed',
];
wp.blocks.getBlockTypes().forEach( block => {
if ( ! registerBlocks.includes( block.name ) ) {
wp.blocks.unregisterBlockType( block.name );
}
} );
const registerEmbedBlocks = [
'twitter',
'youtube',
'wordpress',
];
wp.blocks.getBlockVariations( 'core/embed' ).forEach( block => {
if ( ! registerEmbedBlocks.includes( block.name ) ) {
wp.blocks.unregisterBlockVariation( 'core/embed', block.name );
}
} );
} );
@rocket-martue
Copy link
Author

埋め込みブロックは、registerEmbedBlocksの方に指定する。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment