Skip to content

Instantly share code, notes, and snippets.

@mattheu
Created October 31, 2018 17:14
Show Gist options
  • Save mattheu/7ebc5efd2b2571b928f0495dc6684fd0 to your computer and use it in GitHub Desktop.
Save mattheu/7ebc5efd2b2571b928f0495dc6684fd0 to your computer and use it in GitHub Desktop.
Remove gutenberg core blocks.
// Array of blocks to hide.
// This could come from anywhere - we use localize script and change the blocks to hide depending on post type.
const hiddenBlocks = [ 'hm/myBlock' ];
// Use function below to filter block settings.
// Will hide all 'hiddenBlocks' from the inserter UI
// But if those blocks are already present, or somehow get into the content, they will still work.
wp.hooks.addFilter(
'blocks.registerBlockType',
'hm-gb-blocks/modify-core-blocks',
( settings, blockName ) => {
if ( hiddenBlocks.indexOf( blockName ) === -1 ) {
return settings;
}
return {
...settings,
supports: {
...settings.supports || {},
inserter: false,
},
};
},
50
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment