Skip to main content
Block Variations allow you to define multiple versions of a block that differ by initial attributes or inner blocks. They provide a way to create iterations of existing blocks without building entirely new blocks from scratch.

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
They share the same underlying edit, save, and functionality as the base block.

Example: Embed Block

The core Embed block uses variations for each embed type (YouTube, Twitter, WordPress, etc.):
Each variation appears as a separate option in the inserter, but they’re all the same block type.

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 picker
  • transform - 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 the get_block_type_variations filter:
Variations registered through PHP are merged with JavaScript-registered variations.

Unregistering Variations

Remove variations using unregisterBlockVariation():

Complete Examples

Query Loop Variations

Button Variations

Using isDefault

The isDefault property makes a variation replace the base block in the inserter:

Caveats

  1. Only first isDefault wins: If multiple variations use isDefault, the first registered one takes precedence
  2. Unregister conflicts: Unregister competing default variations before registering yours:

Using isActive

The isActive property helps the editor identify which variation is selected.
The editor compares 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
Use Styles when you need:
  • 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

  1. Always provide a name: Makes variations unregisterable and identifiable
  2. Use isActive: Helps the editor show the correct variation info when selected
  3. Prefer string arrays for isActive: Better specificity handling than functions
  4. Provide good titles/descriptions: Help users choose the right variation
  5. Use appropriate scope: Not all variations need to be in the inserter
  6. Test specificity: Ensure the correct variation is identified as active
  7. Document variations: Comment why each variation exists