Created
February 26, 2022 08:36
-
-
Save carolinan/2b66e074b14d2cf73ad19e002540b436 to your computer and use it in GitHub Desktop.
filter block transforms
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
const { addFilter } = wp.hooks; | |
const { assign, merge } = lodash; | |
const { createBlock } = wp.blocks; | |
function filter(settings) { | |
return assign({}, settings, { | |
transforms: merge(settings.transforms, { | |
from: [ | |
{ | |
type: 'block', | |
blocks: ['core/paragraph'], | |
transform: ({ content }) => { | |
return createBlock('core/heading', { | |
content, | |
className: 'big-headline', | |
}); | |
}, | |
}, | |
], | |
}), | |
}) | |
return settings; | |
} | |
addFilter( | |
'blocks.registerBlockType', | |
'test', | |
filter, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment