What are Block Variations?
Variations differ from the original block by:- Initial attributes: Pre-configured settings when inserted
- Inner blocks: Pre-populated nested content
- Visual appearance: Different icons and titles in the inserter
Example: Embed Block
The core Embed block uses variations for each embed type (YouTube, Twitter, WordPress, etc.):Defining Block Variations
During Block Registration
Define variations in the block configuration:Registering for Existing Blocks
Add variations to existing blocks (including core blocks):Variation Properties
Required Properties
name
Unique identifier for the variation.While technically optional, always provide a unique
name to allow unregistering and distinguish variations.Optional Properties
title
Human-readable title displayed in the inserter.description
Description shown in the inserter.category
Override the block’s category for this variation.keywords
Search terms to help users find the variation.icon
Icon for the variation (Dashicon or custom SVG).attributes
Initial attribute values for the variation.innerBlocks
Initial nested blocks configuration.example
Preview data for the variation (shown on hover).scope
Where the variation appears. Array of:inserter- Shows in the block inserter (default)block- Available for block-level variation pickertransform- Shows in block transformations
isDefault
Mark this variation as the default (replaces the base block in inserter).isActive
Determines which variation is active when a block is selected.Registering in PHP
Register variations server-side using theget_block_type_variations filter:
Variations registered through PHP are merged with JavaScript-registered variations.
Unregistering Variations
Remove variations usingunregisterBlockVariation():
Complete Examples
Social Links Variations
Query Loop Variations
Button Variations
Using isDefault
TheisDefault property makes a variation replace the base block in the inserter:
Caveats
-
Only first isDefault wins: If multiple variations use
isDefault, the first registered one takes precedence - Unregister conflicts: Unregister competing default variations before registering yours:
Using isActive
TheisActive property helps the editor identify which variation is selected.
String Array Method (Recommended)
blockAttributes.providerNameSlug with variationAttributes.providerNameSlug.
Nested Attributes
For nested object attributes:Function Method
For complex logic:Specificity
When multiple variations match, the most specific wins:Specificity only works with string array
isActive. Function-based isActive always returns the first match.Block Variations vs Block Styles
Use Variations when you need:
- Different initial attributes
- Different inner blocks
- Different functionality
- Only visual changes
- Users can switch styles after insertion
- Simple CSS modifications
Combining Both
You can use variations and styles together:Dynamic Variations from WordPress Data
Create variations based on post types, taxonomies, etc.:Best Practices
- Always provide a name: Makes variations unregisterable and identifiable
- Use isActive: Helps the editor show the correct variation info when selected
- Prefer string arrays for isActive: Better specificity handling than functions
- Provide good titles/descriptions: Help users choose the right variation
- Use appropriate scope: Not all variations need to be in the inserter
- Test specificity: Ensure the correct variation is identified as active
- Document variations: Comment why each variation exists
Related Documentation
- Block Styles - Alternative visual styles
- Block Patterns - Predefined block layouts
- Block Transforms - Converting between block types
- PHP Registration - Detailed PHP guide