Created
October 31, 2018 17:14
-
-
Save mattheu/7ebc5efd2b2571b928f0495dc6684fd0 to your computer and use it in GitHub Desktop.
Remove gutenberg core blocks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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