useBlockProps() to manage these wrapper attributes.
Types of block markup
A block can have three distinct types of markup:- Editor markup: Visual representation in the Block Editor (via
Editcomponent) - Save markup: HTML saved to the database (via
savefunction) - Dynamic render markup: Server-generated content (via
render_callbackorrender.php)
Editor markup
Use theuseBlockProps() hook in your Edit component to define the wrapper:
What useBlockProps() provides
TheuseBlockProps() hook automatically adds:
- Unique
idattribute - Accessibility attributes (
role,aria-label,tabindex) - Data attributes for block identification
- The
wp-blockclass - Block-specific class (e.g.,
wp-block-my-plugin-my-block) - Classes and styles from block supports (color, spacing, etc.)
Generated editor markup
Adding custom attributes
Pass additional classes and attributes touseBlockProps():
Save markup
UseuseBlockProps.save() in your save function to ensure proper wrapper attributes:
What useBlockProps.save() provides
- Block-specific class name
- Classes and inline styles from block supports
- Any custom attributes passed as arguments
Generated save markup
Adding custom save attributes
Dynamic render markup (PHP)
For server-rendered blocks, useget_block_wrapper_attributes() in PHP:
Adding custom PHP attributes
Pass an array of custom attributes:get_block_wrapper_attributes() automatically includes classes from block supports like color, spacing, and typography.Wrapper requirements
For bothEdit and save, the wrapper must be:
✅ A standard DOM element (e.g., <div>, <p>, <section>)✅ A React component that forwards all props to native DOM elements ❌ Not a React Fragment (
<Fragment>)❌ Not
<ServerSideRender> component
Valid wrappers
Invalid wrappers
Complete example
Edit component
Save function
Render callback (PHP)
Block supports integration
When you enable block supports inblock.json, the wrapper automatically receives the generated classes:
Next steps
Block supports
Learn about available block supports
Rendering
Understand static vs dynamic rendering