Skip to content

Instantly share code, notes, and snippets.

@carolinan
Created February 26, 2022 08:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carolinan/2b66e074b14d2cf73ad19e002540b436 to your computer and use it in GitHub Desktop.
Save carolinan/2b66e074b14d2cf73ad19e002540b436 to your computer and use it in GitHub Desktop.
filter block transforms
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