@wordpress/blocks
Block registration and serialization utilities.
Key APIs
registerBlockType( name, settings )
Registers a block type.
namestring(namespace/block)settingsobjecttitle,description,category,icon,keywordsattributes: attribute schemasupports: support flagsedit,savetransforms
unregisterBlockType( name )
Removes a previously registered block.
getBlockType( name ) / getBlockTypes()
Get registered block definitions.
createBlock( name, attributes?, innerBlocks? )
Creates a block object.
parse( html ) / serialize( blocks )
Convert between block objects and block HTML.
Attributes
Attributes define how block data is stored and parsed.
js
attributes: {
content: {
type: 'string',
source: 'html',
selector: 'p',
default: '',
},
align: { type: 'string' },
}Common fields:
title,description,category,icon,keywordsattributes: attribute schemasupports: support flagsedit,savetransforms
Transforms
Define how blocks convert to/from other blocks.
js
transforms: {
from: [
{ type: 'block', blocks: [ 'core/paragraph' ], transform: ( attrs ) => ... },
{ type: 'raw', selector: 'p', transform: ( node ) => ... },
],
to: [
{ type: 'block', blocks: [ 'core/heading' ], transform: ( attrs ) => ... },
],
}Transform types:
title,description,category,icon,keywordsattributes: attribute schemasupports: support flagsedit,savetransforms