Blocks
Blocks are an abstract unit for structuring and interacting with content. When composed together they create the content for a webpage. Everything from a paragraph, to a video, to the site title is represented as a block. Blocks come in many different forms but also provide a consistent interface. They can be inserted, moved, reordered, copied, duplicated, transformed, deleted, dragged, and combined. Blocks can also be reused, allowing them to be shared across posts and post types and/or used multiple times in the same post. The settings and content of a block can be customized in three main places:- The block canvas
- The block toolbar
- The block inspector
Composability
Blocks are meant to be combined in different ways. Blocks are hierarchical in that a block can be nested within another block. Nested blocks and their container are also called children and parent respectively. For example, a Columns block can be the parent block to multiple child blocks in each of its columns. The API that governs child block usage is namedInnerBlocks.
Data and Attributes
Blocks understand content as attributes and are serializable to HTML. The block grammar uses HTML comments, either self-closing or with beginning and ending tags. The main tag can contain a JSON object with block configuration. This raw form is the serialized representation:- Static blocks contain rendered content and attributes used to re-render based on changes
- Dynamic blocks require server-side data and rendering during post content generation
- Raw HTML in the content
- Post meta
- Other customizable origins
Block Transforms
Blocks have the ability to be transformed into other block types. This allows operations like:- Converting a paragraph into a heading
- Transforming multiple images into a gallery
- Multi-block selections to compound blocks
Block Variations
Given a block type, a block variation is a predefined set of its initial attributes. This API allows creating a single block from which multiple configurations are possible. Variations provide different possible interfaces, including:- Showing up as entirely new blocks in the library
- Appearing as presets when inserting a new block
Reusable Blocks
A reusable block is an instance of a block (or multiple blocks) that can be inserted and edited in multiple places, remaining in sync everywhere. Any edits to a reusable block appear on every other use of that block. Technical Implementation:- Stored as a hidden post type (
wp_block) - Implemented as dynamic blocks that reference the
post_id - Return the
post_contentfor that block
- Headings with custom colors appearing on multiple pages
- Sidebar widgets appearing on every page
Patterns
A block pattern is a group of blocks combined together to create a design pattern. These provide starting points for building advanced pages and layouts quickly. Key Characteristics:- Can be as small as a single block or as large as a full page
- Once inserted, don’t remain in sync with the original
- Blocks contained are meant to be edited and customized
- Themes can register patterns to offer design language consistent with theme aesthetics
Templates
While the post editor concentrates on post content, the template editor allows declaring and editing an entire site using blocks, from header to footer. Template Structure:- Templates - Describe a full page (home, singular, archive, 404, etc.)
- Template Parts - Reusable areas within templates (header, sidebar, footer)
- Templates and parts can be composed together and registered by a theme
- Fully editable by users in the block editor
- Customized templates are saved in
wp_templatepost type - Include both static pages and dynamic ones (archives, singular, home, 404)
post_content template—this is different from the theme template system described here.
Styles
Styles (formerly known as Global Styles) is both an interface and a configuration system: User Interface: Users access styling controls through the editor’s global styles panel. Configuration System: Atheme.json file absorbs configuration aspects usually scattered through add_theme_support calls, providing:
- What settings should be enabled
- Specific tools a theme offers (custom color palettes)
- Available design tools
- Infrastructure to coordinate styles from WordPress, the theme, and the user