Skip to main content
The @wordpress/blocks package provides the foundational API for working with blocks in WordPress. It includes functions for registering block types, managing block attributes, parsing and serializing blocks, and handling block transformations.

Installation

What is a Block?

A block is the abstract term for units of markup that compose the content or layout of a webpage. Blocks combine concepts of shortcodes, custom HTML, and embeds into a single consistent API.

Core Functions

registerBlockType

Registers a new block type.
Parameters:
  • blockNameOrMetadata (string|Object) - Block type name or metadata
  • settings (Object) - Block configuration
Returns: WPBlockType | undefined

createBlock

Creates a new block instance.
Parameters:
  • name (string) - Block type name
  • attributes (Object) - Block attributes
  • innerBlocks (Array) - Nested blocks
Returns: Object - Block object

parse

Parses post content into blocks.
Parameters:
  • content (string) - Post content
  • options (Object) - Parsing options
Returns: Array - Block list

serialize

Serializes blocks to post content.
Parameters:
  • blocks (Array) - Blocks to serialize
  • options (Object) - Serialization options
Returns: string - Post content

Block Registration

registerBlockCollection

Groups blocks in the inserter by namespace.

registerBlockStyle

Registers alternative block styles.

registerBlockVariation

Registers block variations.

Block Utilities

getBlockType

Retrieves a registered block type.

getBlockTypes

Returns all registered blocks.

hasBlockSupport

Checks if a block supports a feature.

Block Bindings

registerBlockBindingsSource

Registers a block bindings source for dynamic attribute values.

Block Transforms

getBlockTransforms

Retrieves available block transforms.

switchToBlockType

Transforms blocks to another type.

Block Categories

setCategories

Defines available block categories.

Store

The blocks package includes a data store accessible via @wordpress/data:

Learn More