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 markup3
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
Thesave function specifies the HTML structure saved to the database:
Saved markup format
Blocks are stored with HTML comment delimiters: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:- Content should update automatically: Latest Posts block updates when new posts are published
- Markup needs to change globally: Updating block structure automatically applies to all instances
- External data required: Fetching data from APIs or database queries
- User-specific content: Displaying personalized content based on user state
Defining dynamic rendering
Dynamic blocks can use either:1. Render callback in PHP
2. Render template file (render.php)
Inblock.json:
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, returnnull from the save function:
Examples of dynamic blocks
Hybrid approach
Blocks can define both asave 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>:
Comparison
Next steps
Dynamic blocks
Deep dive into creating dynamic blocks
JavaScript in editor
Learn about the JavaScript build process