Transform Directions
Transforms work in two directions:to: Transform this block into other block typesfrom: Create this block from other sources
Transform Types
Gutenberg supports six types of transformations:- block - Convert between block types
- enter - Create blocks from keyboard input (Enter key)
- files - Create blocks from dropped files
- prefix - Create blocks from text prefixes
- raw - Create blocks from raw HTML/DOM
- shortcode - Create blocks from shortcodes
Block Transforms
Convert between different block types using toolbar controls.Basic Block Transform
Block Transform Properties
type (required)
Must be'block'.
blocks (required)
Array of block types this transform applies to. Use'*' for all blocks.
transform (required)
Function that receives block attributes and returns new block(s).isMatch (optional)
Function to determine if transform should be available.isMultiBlock (optional)
Allow transforming multiple selected blocks at once.priority (optional)
Control transform order (lower = higher priority). Default:10.
Block Transform Examples
Transform with InnerBlocks
Multi-Block Transform
Enter Transform
Create blocks when users type and press Enter.--- and pressing Enter creates a separator block.
Enter Transform Properties
- type:
'enter' - regExp: Regular expression to match
- transform: Function returning block(s)
- priority: Optional priority (default: 10)
Enter Transform Examples
Files Transform
Create blocks from dropped or pasted files.Files Transform Properties
- type:
'files' - transform: Function receiving array of files
- isMatch: Optional function to check if files should be handled
- priority: Optional priority (default: 10)
Files Transform Examples
Prefix Transform
Create blocks from text prefixes followed by a space.? creates a question block.
Prefix Transform Properties
- type:
'prefix' - prefix: String to match
- transform: Function receiving remaining content
- priority: Optional priority (default: 10)
Prefix Transform Examples
Raw Transform
Create blocks from raw HTML or DOM nodes (paste, drop, convert to blocks).Raw Transform Properties
- type:
'raw' - transform: Optional function receiving DOM node
- schema: Optional HTML content model for validation
- selector: Optional CSS selector (shorthand for isMatch)
- isMatch: Optional function to check if node matches
- priority: Optional priority (default: 10)
Schemas and Content Models
Define which HTML elements and attributes are allowed:Raw Transform Examples
Shortcode Transform
Create blocks from WordPress shortcodes.Shortcode Transform Properties
- type:
'shortcode' - tag: Shortcode tag (string or array)
- transform: Optional function receiving shortcode attributes
- attributes: Optional attribute mapping object
- isMatch: Optional function to check if shortcode should transform
- priority: Optional priority (default: 10)
Using transform Function
Using attributes Mapping
Ungroup Transform
Define how a container block should be ungrouped:Complete Transform Example
Best Practices
- Preserve user content: Always try to maintain user data during transforms
- Use isMatch wisely: Prevent unwanted transforms with appropriate conditions
- Set appropriate priority: Lower priority for fallback transforms
- Handle edge cases: Test with empty content, special characters, etc.
- Provide two-way transforms: Allow users to undo transforms when possible
- Document transforms: Comment why each transform exists
- Test thoroughly: Verify transforms work with various content types
Common Patterns
Bidirectional Transform
Wildcard Transform
Related Documentation
- Block Variations - Different configurations of blocks
- Block Patterns - Predefined layouts as transforms
- Block Attributes - Understanding block data
createBlockAPI - Creating blocks programmatically