Skip to main content
Blocks are the fundamental units of markup that compose content and layout in the WordPress block editor. This guide walks you through creating custom blocks from registration to implementation.

What is a Block?

A “block” is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage. The idea combines concepts of what in WordPress we traditionally achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience.

Block Registration

Every block starts by registering a new block type definition using the registerBlockType function from the @wordpress/blocks package.

Basic Block Structure

Block Name

The name for a block is a unique string that identifies it. Names must be structured as namespace/block-name, where namespace is the name of your plugin or theme.
Important: Block names cannot be changed later without consequences. The block name is stored in the post content, so changing it requires editing all affected posts or running database scripts.

Namespace Best Practices

  • Use your actual plugin/theme name: my-awesome-plugin/block-name
  • Avoid generic names like editorial/, block/, or create-block/
  • Use the same namespace for all blocks in your plugin/theme
  • Make it unique to prevent conflicts with other plugins

Block Configuration Properties

Required Properties

title

The display title for your block, which can be translated. Appears in the inserter and throughout the editor.

category

Blocks are grouped into categories. Core categories include:
  • text
  • media
  • design
  • widgets
  • theme
  • embed

Optional Properties

description

A short description shown in the Block Tab in the Settings Sidebar.

icon

An icon to identify your block. Can be a Dashicon slug or custom SVG.

keywords

Terms that help users discover your block while searching.

The Edit Function

The edit function defines what users see in the block editor when editing content.

Using useBlockProps

Always use useBlockProps() to ensure your block works correctly with the editor:
The useBlockProps hook:
  • Adds necessary CSS classes
  • Handles block supports attributes
  • Ensures proper editor integration

Accessing Attributes

The Save Function

The save function defines the final markup saved to the database and rendered on the frontend.
Always use useBlockProps.save() in the save function to ensure attributes from block supports are properly saved.

Installation

To use the blocks package:

Creating Your First Block

1

Set up your development environment

Install Node.js and npm, then set up a build process for JSX.
2

Create your block registration file

Create a new JavaScript file and import the necessary functions:
3

Register your block

Call registerBlockType with your block name and configuration:
4

Enqueue your script

Register and enqueue your block script in PHP:
5

Test your block

Open the WordPress editor and insert your new block from the inserter.

Block Collections

You can group related blocks into collections:
All blocks with the my-plugin namespace will appear under this collection in the inserter.

Common Block Patterns

Simple Content Block

Next Steps

API Reference

For complete API documentation, see: