@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.
attributes: {
content: {
type: 'string',
source: 'html',
selector: 'p',
default: '',
},
align: { type: 'string' },
}
Common fields:
type:string | number | boolean | object | arraysource:attribute | html | text | children | query | metaselector,attribute,meta,default
Transforms
Define how blocks convert to/from other blocks.
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:
block(block-to-block)raw(HTML → block)shortcode(shortcode → block)prefix(typed prefix → block)