Title: How to register block variations with PHP
Author: Justin Tadlock
Published: March 14, 2024

---

 * [Showcase](https://wordpress.org/showcase/)
 * [Plugins](https://wordpress.org/plugins/)
 * [Themes](https://wordpress.org/themes/)
 * [Hosting](https://wordpress.org/hosting/)
 * [News](https://wordpress.org/news/)
    - [Learn WordPress](https://learn.wordpress.org/)
    - [Documentation](https://wordpress.org/documentation/)
    - [Education](https://wordpress.org/education/)
    - [Forums](https://wordpress.org/support/forums/)
    - [Developers](https://developer.wordpress.org/)
    - [Blocks](https://wordpress.org/blocks/)
    - [Patterns](https://wordpress.org/patterns/)
    - [Photos](https://wordpress.org/photos/)
    - [Openverse ︎](https://openverse.org/)
    - [WordPress.tv ︎](https://wordpress.tv/)
 *  - [About WordPress](https://wordpress.org/about/)
    - [Make WordPress](https://make.wordpress.org/)
    - [Events](https://events.wordpress.org/)
    - [Five for the Future](https://wordpress.org/five-for-the-future/)
    - [Enterprise](https://wordpress.org/enterprise/)
    - [Gutenberg ︎](https://wordpress.org/gutenberg/)
    - [Job Board ︎](https://jobs.wordpress.net/)
 * [Swag ︎](https://mercantile.wordpress.org/)
 * [Get WordPress](https://wordpress.org/download/)

Search in WordPress.org

 [ Get WordPress ](https://wordpress.org/download/)

[WordPress Developer Blog](https://developer.wordpress.org/news)

How to register block variations with PHP

 * [Snippets](https://developer.wordpress.org/news/snippets/)
    - [Blocks](https://developer.wordpress.org/news/category/blocks/)
    - [Concepts](https://developer.wordpress.org/news/category/concepts/)
    - [Common APIs](https://developer.wordpress.org/news/category/common-apis/)
    - [Design](https://developer.wordpress.org/news/category/design/)
    - [Playground](https://developer.wordpress.org/news/category/playground/)
    - [Plugins](https://developer.wordpress.org/news/category/plugins/)
    - [Themes](https://developer.wordpress.org/news/category/themes/)
 *  - [About this site](https://developer.wordpress.org/news/about/)
    - [Updates](https://developer.wordpress.org/news/category/updates/)
    - [How to contribute](https://developer.wordpress.org/news/how-to-contribute/)
    - [Tips and guidelines](https://developer.wordpress.org/news/tips-and-guidelines-for-writers/)
 * [Subscribe](https://developer.wordpress.org/news/subscribe/)
 * [Developer Resources](https://developer.wordpress.org/)

 * [Snippets](https://developer.wordpress.org/news/snippets/)
    - [Blocks](https://developer.wordpress.org/news/category/blocks/)
    - [Concepts](https://developer.wordpress.org/news/category/concepts/)
    - [Common APIs](https://developer.wordpress.org/news/category/common-apis/)
    - [Design](https://developer.wordpress.org/news/category/design/)
    - [Playground](https://developer.wordpress.org/news/category/playground/)
    - [Plugins](https://developer.wordpress.org/news/category/plugins/)
    - [Themes](https://developer.wordpress.org/news/category/themes/)
 *  - [About this site](https://developer.wordpress.org/news/about/)
    - [Updates](https://developer.wordpress.org/news/category/updates/)
    - [How to contribute](https://developer.wordpress.org/news/how-to-contribute/)
    - [Tips and guidelines](https://developer.wordpress.org/news/tips-and-guidelines-for-writers/)
 * [Subscribe](https://developer.wordpress.org/news/subscribe/)
 * [Developer Resources](https://developer.wordpress.org/)

# How to register block variations with PHP

By [Justin Tadlock](https://profiles.wordpress.org/greenshady/)

March 14, 2024

[Blocks](https://developer.wordpress.org/news/category/blocks/), [Plugins](https://developer.wordpress.org/news/category/plugins/),
[Themes](https://developer.wordpress.org/news/category/themes/)

WordPress will soon ship with a new method of registering custom block variations.
In the past, you would have typically registered them via the JavaScript-based [Variations API](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/),
but you’ll be able to define variations using a dedicated PHP filter hook in WordPress
6.5.

The hook addition was part of a [larger performance-specific patch](https://core.trac.wordpress.org/changeset/57315),
which you can read more about in the [Dev Note](https://make.wordpress.org/core/2024/02/29/performance-improvements-for-registering-block-variations-with-callbacks/).
The great thing for plugin and theme authors is that it makes the process of registering
variations easier.

This change also opens more opportunities to integrate with the block system for
developers who are less comfortable with JavaScript. So let’s go ahead and dive 
into what will be possible in WordPress 6.5.

If you’re unfamiliar with block variations, check out [An introduction to block variations](https://developer.wordpress.org/news/2023/08/29/an-introduction-to-block-variations/)
here on the Developer Blog.

Technically, it’s long been possible to add variations via PHP by injecting them
via the [`register_block_type_args`](https://developer.wordpress.org/reference/hooks/register_block_type_args/)
filter hook, but this method was undocumented and not made clear to developers. 
The new method in WordPress 6.5 also limits the scope of what you filter since it
is specific to block variations rather than the entire block.

Table of Contents

 1. [Block variations hook and callback](https://developer.wordpress.org/news/2024/03/14/how-to-register-block-variations-with-php/#block-variations-hook-and-callback)
 2. [Building a custom variation](https://developer.wordpress.org/news/2024/03/14/how-to-register-block-variations-with-php/#building-a-custom-variation)
 3. [Customizing the variation arguments](https://developer.wordpress.org/news/2024/03/14/how-to-register-block-variations-with-php/#customizing-the-variation-arguments)
 4. [A future API?](https://developer.wordpress.org/news/2024/03/14/how-to-register-block-variations-with-php/#a-future-api)

## Block variations hook and callback

Technically, WordPress 6.5 doesn’t create a standard set of API functions to use
for registering variations. But it does add a new filter hook named `get_block_type_variations`,
which lets you inject custom variations from either a plugin or theme.

Take a look at the `get_block_type_variations` filter hook:

    ```php
    apply_filters(
    	'get_block_type_variations',
    	array $variations,
    	WP_Block_Type $block_type
    );
    ```

As shown, the hook can pass up to two parameters to any filters that are applied
to it:

 * **`$variations`:** An array of registered variations for the specific block.
 * **`$block_type`:** An instance of the [`WP_Block_Type`](https://developer.wordpress.org/reference/classes/wp_block_type/)
   class, representing a registered block type.

When defining a filter for the hook, you will almost always need both of these parameters.
So be sure to set the `$accepted_args` parameter to `2` when calling the [`add_filter()`](https://developer.wordpress.org/reference/functions/add_filter/)
function.

The following is an example of a fictional filter on `get_block_type_variations`
to familiarize you with how it should be formatted:

    ```php
    add_filter( 'get_block_type_variations', 'themeslug_block_type_variations', 10, 2 );

    function themeslug_block_type_variations( $variations, $block_type ) {

    	if ( 'namespace/block-a' === $block_type->name ) {
    		// Add variations to the `$variations` array.
    	} elseif ( 'namespace/block-b' === $block_type->name ) {
    		// Add more variations to the `$variations` array.
    	}

    	return $variations;
    }
    ```

It’s always necessary to run an `if` conditional check to determine whether the 
block is the one you want to define a variation for. You can use the `name` property
of the `$block` parameter to do this.

Your filter function can also add multiple variations for a single block or define
variations for multiple blocks by appending them to the `$variations` parameter.

## Building a custom variation

Now it’s time to get to the fun part: registering a custom block variation!

For this example, let’s use PHP to recreate a JavaScript-based example from the 
[Variations API](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/)
Block Editor Handbook documentation. The variation makes a single attribute change:
it moves the media section from the Media & Text block to the right.

When inserted into the Block Editor, the variation will look like this:

![WordPress post editor with a single Media & Text block in the content area. The
media upload field is aligned to the right and the content on the left.](https://
developer.wordpress.org/news/files/2024/03/php-variation-media-text-default.webp)

To create this variation, the first thing you need to do is add a filter on `get_block_type_variations`.
And because you know the block type you want to target (Media & Text), go ahead 
and add a check for it by adding this code to either your theme’s `functions.php`
or your plugin file:

    ```php
    add_filter( 'get_block_type_variations', 'themeslug_block_type_variations', 10, 2 );

    function themeslug_block_type_variations( $variations, $block_type ) {

    	if ( 'core/media-text' === $block_type->name ) {
    		// Add your variation here.
    	}

    	return $variations;
    }
    ```

Now you must decide which attributes make this variation different from the default
block. For the Media & Text block, you can find its available attributes via its
[`block.json`](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/media-text/block.json)
file. In this case, you’ll set the `mediaPosition` attribute to `right` (it has 
a default value of `left`).

There are several other arguments that you can set for a variation, which we’ll 
get to. For now, update your `themeslug_block_type_variations()` function so that
it looks like this:

    ```php
    add_filter( 'get_block_type_variations', 'themeslug_block_type_variations', 10, 2 );

    function themeslug_block_type_variations( $variations, $block_type ) {

    	if ( 'core/media-text' === $block_type->name ) {
    		$variations[] = array(
    			'name'       => 'themeslug-media-right',
    			'title'      => __( 'Media & Text: Right', 'themeslug' ),
    			'isActive'   => array(
    				'mediaPosition' 
    			),
    			'attributes' => array(
    				'mediaPosition' => 'right'
    			)
    		);
    	}

    	return $variations;
    }
    ```

Note the arguments that this variation sets: `name`, `title`, `isActive`, and `attributes`.
These are the four arguments that I consider “must haves” for nearly every variation.

This is a relatively basic example that illustrates how PHP-based variations work,
and you can certainly build more complex variations for your projects. A good exercise
beyond this tutorial would be to walk through [Building a book review grid with a Query Loop block variation](https://developer.wordpress.org/news/2022/12/20/building-a-book-review-grid-with-a-query-loop-block-variation/)
and convert the code to PHP.

## Customizing the variation arguments

I won’t dive too deeply into the various arguments for registering custom block 
variations. These are documented well in the [Variations](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/)
handbook doc. But I do want to list the basic definitions of each and note the differences
between using PHP and JavScript.

You can define any of the following arguments for your variation:

 * **`name`:** A unique identifier for the variation. It’s best practice to prefix
   this with your theme/plugin slug.
 * **`title`:** An optional human-readable title that should be internationalized.
 * **`description`:** A description of your variation that should be internationalized.
 * **`category`:** A block category to place the variation under if different from
   the block itself.
 * **`keywords`:** An array of terms that help users discover the variation when
   searching.
 * **`icon`:** A [Dashicon](https://developer.wordpress.org/resource/dashicons/)
   string representing the icon you want to show. Unlike JavaScript-based variations,
   you cannot assign a custom SVG.
 * **`attributes`:** An array of attributes that define your variation as different
   from the default.
 * **`innerBlocks`:** The initial configuration of nested blocks (if the block allows
   nested blocks).
 * **`example`:** An array of structured data used in the block’s preview.
 * **`scope`:** An array of scopes where the variation is applicable, which includes`
   block`, `inserter`, and `transform`.
 * **`isDefault`:** Whether the variation should be the default.
 * **`isActive`:** An array of block attributes that should be used to determine
   whether the variation is active. Unlike JavaScript-registered variations, you
   cannot pass a custom callback that determines the active state.

It’s important to reiterate the two major differences between registering with JavaScript
and PHP from the above list. First, you cannot use a custom `icon` and are limited
to the available Dashicons.

But the biggest limitation may be with the `isActive` argument. For simple variations,
passing an array of attributes to check should be OK. But for more complex variations
that require a custom callback to determine the active state, it’s best to use JavaScript.

Outside of those limitations, block variation arguments work exactly the same using
PHP as they do with JavaScript.

## A future API?

There is currently an [open ticket](https://github.com/WordPress/gutenberg/issues/47170)
to add a standard `register_block_variation()` PHP function, which would be the 
equivalent of the `registerBlockVariation()` JavaScript function. This ticket does
not yet have a pull request associated with it, so it’s open for anyone to pick 
up if they want to include the function in Core.

Until then, the `get_block_type_variations` filter hook is always available.

_Props to [@ndiego](https://profiles.wordpress.org/ndiego/) and [@eidolonnight](https://profiles.wordpress.org/eidolonnight/)
for editorial review and [@ntsekouras](https://profiles.wordpress.org/ntsekouras/)
and [@gziolo](https://profiles.wordpress.org/gziolo/) for help with a technical 
question._

**Share the post: **

**Categories:** [Blocks](https://developer.wordpress.org/news/category/blocks/),
[Plugins](https://developer.wordpress.org/news/category/plugins/), [Themes](https://developer.wordpress.org/news/category/themes/)

**Tags:** [Block variations](https://developer.wordpress.org/news/tag/block-variations/)

## 24 responses to “How to register block variations with PHP”

 1.   ![Pro Avatar](https://secure.gravatar.com/avatar/b0ad8f8f9dd873d481d75dca13dcdfda78227dffb0104d2f796c5567a776e4f7?
      s=40&d=identicon&r=g)
 2.   [Pro](http://Capcutpremium.com)
 3.   [March 15, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-3818)
 4.   Can i use it with my existing apk site
 5.   [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=3818#respond)
 6.    a. ![Justin Tadlock Avatar](https://secure.gravatar.com/avatar/8013a62d7397c006bae48b96d6832a573ea71a7d5d3597fe584210567b508c05?
          s=40&d=identicon&r=g)
       b. [Justin Tadlock](https://profiles.wordpress.org/greenshady/)
       c. [March 20, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-3896)
       d. If this site is built on WordPress, yes.
       e. [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=3896#respond)
 7.   ![Kaledri Avatar](https://secure.gravatar.com/avatar/e4cebafdc9286d418b12a341cdb0a1f766c68cdfd7b3a927e578d2a186ec95ed?
      s=40&d=identicon&r=g)
 8.   [Kaledri](https://palpitedokaledrihoje.com.br/)
 9.   [March 24, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-3997)
 10.  Thanks appriciate it!
 11.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=3997#respond)
 12.  ![Grégoire Noyelle Avatar](https://secure.gravatar.com/avatar/2ad809959fb7c1e8824ae3338f0ee87458a68cfee3fba9260dae7d29d60d8c9d?
      s=40&d=identicon&r=g)
 13.  [Grégoire Noyelle](https://www.gregoirenoyelle.com)
 14.  [April 1, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-4190)
 15.  Thank you, Justin.
       Brian made a very good video on how to use this feature with
      post meta: [https://youtu.be/qD5U7TNUKTQ?si=RmgQuYo_XpxAlvmK](https://youtu.be/qD5U7TNUKTQ?si=RmgQuYo_XpxAlvmK)
 16.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=4190#respond)
 17.  ![Rich Holman Avatar](https://secure.gravatar.com/avatar/247b532f1e25e4e059e968de102eba47f3ed1c449d6b39956f700bef67583aba?
      s=40&d=identicon&r=g)
 18.  [Rich Holman](http://dogwonder.co.uk)
 19.  [April 4, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-4285)
 20.  This is excellent! I always messed up the Javascript method.
 21.  One variation I often make is the core/group grid variation.
 22.  I tried this here but maybe `get_block_type_variations` doesn’t yet support core/
      group?
 23.  `if ( 'core/group' === $block_type->name ) {
       $variations[] = array( 'name' =
      > 'group-grid', 'title' => 'Group grid', 'icon' => 'grid-view', 'attributes' 
      => array( 'layout' => array( 'type' => 'grid' ), ), ); }
 24.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=4285#respond)
 25.   a.  ![Damien Carbery Avatar](https://secure.gravatar.com/avatar/dc36accfe96d4494975e7ba096bdeee2d452fa00e9ecdcac2fcb1b3c65f3927b?
           s=40&d=identicon&r=g)
       b.  [Damien Carbery](https://www.damiencarbery.com)
       c.  [April 23, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-5580)
       d.  I too am having an issue with a core/group variation. It doesn’t seem to work
           in PHP but JS is fine.
       e.  PHP (not working):
       f.  [code]
            $variations[] = array( ‘name’ =&gt; ‘dcwd-update-info’, ‘title’ =&gt;‘
           Update Info’, ‘icon’ =&gt; ‘book-alt’, ‘attributes’ =&gt; array( ‘className’
           =&gt; ‘is-style-group-info’ ), // add class ‘innerBlocks’ =&gt; array( array(‘
           core/paragraph’, array( ‘content’ =&gt; ‘<strong>dd MM YY</strong>: information
           about the update …’, ) ), ), ); [/code]
       g.  JS (working):
       h.  [code]
            wp.blocks.registerBlockVariation( ‘core/group’, { name: ‘dcwd-group-
           update’, title: ‘Update info’, attributes: { className: ‘is-style-group-info’,},
           innerBlocks: [ [ ‘core/paragraph’, { content: ‘<strong>’ + new Date().toLocaleDateString(‘
           en-us’, { year:"numeric", month:"long", day:"numeric"}) + ‘</strong>: Info 
           about update…’, } ], ], } ); [/code]
       i.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=5580#respond)
       j.  ![Damien Carbery Avatar](https://secure.gravatar.com/avatar/dc36accfe96d4494975e7ba096bdeee2d452fa00e9ecdcac2fcb1b3c65f3927b?
           s=40&d=identicon&r=g)
       k.  [Damien Carbery](https://www.damiencarbery.com)
       l.  [April 23, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-5581)
       m.  Ouch, my code and ‘strong’ tags got messed up. Here’s the PHP and JS code:
           
           [https://pastebin.com/raw/b2UGTybp](https://pastebin.com/raw/b2UGTybp)
       n.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=5581#respond)
 26.  ![RS Avatar](https://secure.gravatar.com/avatar/ca02c2c971b88803eedeefa285414ffe451158a3848bb51894a3a447efecb83c?
      s=40&d=identicon&r=g)
 27.  RS
 28.  [April 27, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-5719)
 29.  This is a great tutorial! It’s working for me, but is there an argument to set
      the open target for core/buttons? It’s opening the link on the same tab, I want
      it to open in a new tab, so ‘_blank’.
 30.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=5719#respond)
 31.  ![Kane Hocking Avatar](https://secure.gravatar.com/avatar/f534fb5aebfd669a1df75ef91006f7e6b15e5d394b04213a740f4c11a3dd37d2?
      s=40&d=identicon&r=g)
 32.  [Kane Hocking](https://capycutapk.com/)
 33.  [May 8, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-5884)
 34.  Man this would be really helpful because JS has been a huge pain in the ____.
      Having this would solve that issue and ultimately lead to more better website
      performances. hahaha
 35.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=5884#respond)
 36.  ![Calculadora Alicia Avatar](https://secure.gravatar.com/avatar/b8395ec69475be09025c0edf6ec8ae5d569cbff70c57126997d564f65d8b4957?
      s=40&d=identicon&r=g)
 37.  [Calculadora Alicia](http://calculadoradealicia.es/)
 38.  [May 11, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-5949)
 39.  I used it on my WordPress blog and it worked extremely well.
 40.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=5949#respond)
 41.  ![wamwebdev Avatar](https://secure.gravatar.com/avatar/d8fd64d5924f06beeab3c2a96167c15d984bdec8329782d36bd2a53631d1029f?
      s=40&d=identicon&r=g)
 42.  [wamwebdev](https://profiles.wordpress.org/wamwebdev/)
 43.  [June 4, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-6606)
 44.  This is great. Has anyone managed to get this working for ‘core/query’? I understand
      that the ‘isActive’ may be problematic here(?) as in my JS version I’m using 
      a callback to check both namespace and query.postType, but setting it to just‘
      namespace’ should work in principle?
 45.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=6606#respond)
 46.  ![Mahesh Waghmare Avatar](https://secure.gravatar.com/avatar/4c89dc1bb610b8fe3109a8f396f71c651bb779f7b0f7c3f2bc6d6f2cc3b41fb9?
      s=40&d=identicon&r=g)
 47.  Mahesh Waghmare
 48.  [July 18, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-7495)
 49.  It not works with PHP though filter `get_block_type_variations` anymore.
 50.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=7495#respond)
 51.   a. ![Justin Tadlock Avatar](https://secure.gravatar.com/avatar/8013a62d7397c006bae48b96d6832a573ea71a7d5d3597fe584210567b508c05?
          s=40&d=identicon&r=g)
       b. [Justin Tadlock](https://profiles.wordpress.org/greenshady/)
       c. [July 19, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-7527)
       d. I just tested this with WordPress 6.6 and can say that it still works as described
          in the article. If you can share your code, I’m happy to give a test.
       e. [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=7527#respond)
 52.  ![Cooper Avatar](https://secure.gravatar.com/avatar/bb069f20334458ffe96af173efaad8ee9098e3b034382afce7a21bcfa6bd9563?
      s=40&d=identicon&r=g)
 53.  Cooper
 54.  [July 21, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-7584)
 55.  Wow, this is a life saver. Thanks!
 56.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=7584#respond)
 57.  ![zainab Avatar](https://secure.gravatar.com/avatar/7b1a2dce73085ed5647d523ceee25cb57b7d4f467e46615707bc9e23a98344e0?
      s=40&d=identicon&r=g)
 58.  [zainab](https://topfollowerpro.com)
 59.  [September 5, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-11646)
 60.  Man this would be really helpful because JS has been a huge pain in the ____.
      Having this would solve that issue and ultimately lead to more better website
      performances
 61.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=11646#respond)
 62.  ![Jessica Wade Avatar](https://secure.gravatar.com/avatar/00451a7a7da082c41ae0e13021be66518cd83d52ee83444eb15bc900a12b8b08?
      s=40&d=identicon&r=g)
 63.  Jessica Wade
 64.  [October 1, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-12462)
 65.  I am grateful for this information concerning block variation registration with
      PHP. It is quite useful for developers who wanted to improve their Gutenberg 
      block experience in such a way. I like the sequential approach with explanations–
      it helps a lot in simplification of the task. Can’t wait to test it!
 66.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=12462#respond)
 67.  ![stbemu codes Avatar](https://secure.gravatar.com/avatar/0bee42ebf4f26a68bc24f6243bcb97dcc3897a806064b9f9115e84100ec6f83d?
      s=40&d=identicon&r=g)
 68.  [stbemu codes](https://stbemuiptv.codes/)
 69.  [October 1, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-12463)
 70.  This is a great tutorial! It’s working for me, but is there an argument to set
      the open target for core/buttons
 71.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=12463#respond)
 72.  ![julin Avatar](https://secure.gravatar.com/avatar/7913f52840d8343a020dbe7d5bed9617993bda0ad030b53670d07a0885afda76?
      s=40&d=identicon&r=g)
 73.  julin
 74.  [October 4, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-12480)
 75.  this helped me a lot. great work
 76.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=12480#respond)
 77.  ![Michel Avatar](https://secure.gravatar.com/avatar/d49e487cd99ba9f055072638f64c99386a5ada84738893414bf14e1ec80a7bb9?
      s=40&d=identicon&r=g)
 78.  Michel
 79.  [October 5, 2024](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-12496)
 80.  Woho, this is save my time. Thanks alott
 81.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=12496#respond)
 82.  ![jack112233 Avatar](https://secure.gravatar.com/avatar/5cef561072e22c88b7da0a08274e4852d6b8722130fb64398fc8b1d0510e805f?
      s=40&d=identicon&r=g)
 83.  [jack112233](https://menurecords.com/)
 84.  [January 25, 2025](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-16135)
 85.  However, until such an API is developed, the get_block_type_variations filter
      hook serves as the primary method for PHP-based block variation registration.
 86.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=16135#respond)
 87.  ![jennaqwilson132 Avatar](https://secure.gravatar.com/avatar/c33882fe83735b326e8fd2b3aff58d7b2df142751378c125ee90fb1e1dc5875e?
      s=40&d=identicon&r=g)
 88.  [jennaqwilson132](https://profiles.wordpress.org/jennaqwilson132/)
 89.  [January 27, 2025](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-16271)
 90.  To register block variations with PHP in WordPress, you can use the `register_block_type`
      and `register_block_variation` functions. First, define the block type with `
      register_block_type` or rely on a `block.json` file for configuration. Then, 
      dynamically add variations using `register_block_variation`, specifying properties
      like name, title, and custom attributes. This approach helps create reusable 
      customizations for Gutenberg blocks efficiently.
 91.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=16271#respond)
 92.  ![Patty69 Avatar](https://secure.gravatar.com/avatar/21e1f024c2721f516f67fb71278653222aa1b4306738818dd0683c70d19979d1?
      s=40&d=identicon&r=g)
 93.  [Patty69](https://kinemasterdl.com)
 94.  [February 27, 2025](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-17300)
 95.  Yes, My blog performance improved due to block variations with PHP. Thanks
 96.  [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=17300#respond)
 97.  ![Xeiver Avatar](https://secure.gravatar.com/avatar/01447e5cede54eebe43ec96422d601f7752469e8154994fcdfadd9413d8ca70e?
      s=40&d=identicon&r=g)
 98.  Xeiver
 99.  [March 24, 2025](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-17497)
 100. Does using get_block_type_variations impact performance compared to the JavaScript-
      based Variations API, especially in large-scale projects?
 101. [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=17497#respond)
 102. ![dohaf29 Avatar](https://secure.gravatar.com/avatar/7202c0baa1fbba43cb26f685f5a5cb01270728a0cbe58ef1dcc881b695bd5873?
      s=40&d=identicon&r=g)
 103. dohaf29
 104. [June 3, 2025](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/#comment-18606)
 105. This new PHP-based method of registering block variations in WordPress 6.5 could
      be a game changer for developers building custom app landing pages — especially
      for something like a [Spotify X APK](https://spotiffyx.com/) download page. You
      can now dynamically adjust content blocks, like download buttons or version notices,
      without touching JavaScript. Streamlined customization through PHP means faster
      deployment and better control over layout variations based on APK version or 
      device compatibility.
 106. [Reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?replytocom=18606#respond)

### Leave a Reply 󠀁[Cancel reply](https://developer.wordpress.org/news/2024/03/how-to-register-block-variations-with-php/?output_format=md#respond)󠁿

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

 Save my name, email, and website in this browser for the next time I comment.

 Notify me of follow-up comments by email.

 Notify me of new posts by email.

Δ

## Have an idea for a new post?

### 󠀁[Learn how to contribute](https://developer.wordpress.org/news/how-to-contribute/)󠁿

Share your knowledge with fellow WordPress developers.

Search

### 󠀁[Review tips and guidelines](https://developer.wordpress.org/news/tips-and-guidelines-for-writers/)󠁿

Everything you need to know about writing for the Blog.

## Subscribe to the Blog

  Email Address

 Join 1,771 other subscribers

 * [About](https://wordpress.org/about/)
 * [News](https://wordpress.org/news/)
 * [Hosting](https://wordpress.org/hosting/)
 * [Privacy](https://wordpress.org/about/privacy/)

 * [Showcase](https://wordpress.org/showcase/)
 * [Themes](https://wordpress.org/themes/)
 * [Plugins](https://wordpress.org/plugins/)
 * [Patterns](https://wordpress.org/patterns/)

 * [Learn](https://learn.wordpress.org/)
 * [Documentation](https://wordpress.org/documentation/)
 * [Developers](https://developer.wordpress.org/)
 * [WordPress.tv ](https://wordpress.tv/)

 * [Get Involved](https://make.wordpress.org/)
 * [Events](https://events.wordpress.org/)
 * [Donate ](https://wordpressfoundation.org/donate/)
 * [Swag ](https://mercantile.wordpress.org/)

 * [WordPress.com ](https://wordpress.com/?ref=wporg-footer)
 * [Matt ](https://ma.tt/)
 * [bbPress ](https://bbpress.org/)
 * [BuddyPress ](https://buddypress.org/)

 * [Visit our X (formerly Twitter) account](https://www.x.com/WordPress)
 * [Visit our Bluesky account](https://bsky.app/profile/wordpress.org)
 * [Visit our Mastodon account](https://mastodon.world/@WordPress)
 * [Visit our Threads account](https://www.threads.net/@wordpress)
 * [Visit our Facebook page](https://www.facebook.com/WordPress/)
 * [Visit our Instagram account](https://www.instagram.com/wordpress/)
 * [Visit our LinkedIn account](https://www.linkedin.com/company/wordpress)
 * [Visit our TikTok account](https://www.tiktok.com/@wordpress)
 * [Visit our YouTube channel](https://www.youtube.com/wordpress)
 * [Visit our Tumblr account](https://wordpress.tumblr.com/)

![Code is Poetry](https://s.w.org/style/images/code-is-poetry-for-dark-bg.svg)

 The WordPress® trademark is the intellectual property of the WordPress Foundation.