Skip to main content
Blocks can generate front-end output in two ways: static rendering (fixed HTML saved to the database) or dynamic rendering (server-generated HTML on each request).
Read Static vs. dynamic blocks: What’s the difference? for a great introduction to this topic.

Static rendering

Blocks with static rendering produce fixed HTML that is stored in the database when saved. This HTML remains unchanged unless manually edited in the Block Editor.

How static rendering works

1

User edits block

Content is modified in the Block Editor
2

Save function executes

The save function generates HTML markup
3

HTML stored in database

Generated markup is saved within block delimiters
4

Front-end display

Stored HTML is retrieved and displayed on page load

Defining static rendering

The save function specifies the HTML structure saved to the database:

Saved markup format

Blocks are stored with HTML comment delimiters:
On the front end, only the inner HTML is displayed:

When to use static rendering

✅ Content that doesn’t need to update automatically
✅ Simple blocks with fixed structure
✅ Blocks where performance is critical
✅ Content that should remain stable even if plugin is deactivated

Examples of static blocks

Dynamic rendering

Blocks with dynamic rendering generate content server-side upon each request. The database stores block attributes but not the full HTML output.

How dynamic rendering works

1

User edits block

Attributes are modified in the Block Editor
2

Attributes stored

Only block attributes saved to database
3

Page requested

Front-end page is loaded
4

Server renders block

PHP render callback generates HTML dynamically

When to use dynamic rendering

Use dynamic blocks when:
  1. Content should update automatically: Latest Posts block updates when new posts are published
  2. Markup needs to change globally: Updating block structure automatically applies to all instances
  3. External data required: Fetching data from APIs or database queries
  4. User-specific content: Displaying personalized content based on user state
Changing the save function of an existing static block can cause validation errors. Dynamic rendering avoids this issue.

Defining dynamic rendering

Dynamic blocks can use either:

1. Render callback in PHP

2. Render template file (render.php)

In block.json:
In render.php:

Render function parameters

Both methods receive three parameters:
array
The array of block attributes
string
The markup saved in the database (from save function if defined)
WP_Block
The instance of the WP_Block class with block metadata

Dynamic block with null save

For purely dynamic blocks, return null from the save function:

Examples of dynamic blocks

Hybrid approach

Blocks can define both a save function and dynamic rendering. The dynamic rendering takes precedence, but the saved HTML serves as a fallback:
This approach is useful for maintaining content if the block’s plugin is deactivated.

Server-side rendering in the editor

For dynamic blocks, preview the server-rendered output in the editor using <ServerSideRender>:
ServerSideRender makes an API request on every attribute change. For better performance, build a custom Edit component that mirrors the server output.

Comparison

Next steps

Dynamic blocks

Deep dive into creating dynamic blocks

JavaScript in editor

Learn about the JavaScript build process