Skip to content

Allow blocks to be renamed via a block template #77436

Closed

Description

@eric-michel

What problem does this address?

Block renaming support was added for most blocks over a year ago, and it's really great for making the purpose of blocks clear to our users.

It would be incredibly helpful if custom names could be applied to blocks within a block template as well. For instance, we're creating a top level container block that exists on every page. At the start of that container, I would like a Spacer block renamed to "Space Below Header" and one at the end of that container called "Space Above Footer". Best I can tell, this is not currently possible.

What is your proposed solution?

Add block renaming support to the block template array. Maybe something like:

            array( 'core/spacer', array(
                'name' => 'Space Below Header',
            ) ),

Activity

  1. t-hamano commented on Apr 17, 2026

    @t-hamano
    Contributor

    If I understand correctly, can't we apply a custom name like this?

    add_action( 'init', function () {
        register_block_template(
            'myplugin//two-spacers',
            array(
                'title'   => 'Two Spacers',
                'content' => '<!-- wp:spacer {"metadata":{"name":"Space Below header"}} -->
    <div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
    <!-- /wp:spacer -->
    
    <!-- wp:spacer {"height":"50px","metadata":{"name":"Space above footer"}} -->
    <div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>
    <!-- /wp:spacer -->',
            )
        );
    } );
  2. Mamaduka commented on Apr 17, 2026

    @Mamaduka
    Member

    It should be possible today, just requires setting up the metadata.name argument.

  3. eric-michel commented on Apr 17, 2026

    @eric-michel
    Author

    @t-hamano I did not realize the method you described was possible! I will give that a go.

    @Mamaduka I'm not sure I follow your suggestion. I have looked for more documentation on block templates and it seems fairly spotty (at least from what I've been able to find, which is all very basic). If what I described is possible now without having to write the full markup of the block as @t-hamano suggests, I'd love more details on that.

  4. t-hamano commented on Apr 18, 2026

    @t-hamano
    Contributor

    I believe this issue relates to documentation improvements rather than feature enhancements or bugs.

  5. Mamaduka commented on Apr 20, 2026

    @Mamaduka
    Member

    @eric-michel, I was referring to post type templates, which can be defined as a PHP array - https://developer.wordpress.org/block-editor/reference-guides/block-api/block-templates/. Based on your example in the description, I thought you were using that.

  6. eric-michel commented on Apr 21, 2026

    @eric-michel
    Author

    Ok, with y'all's help I have figured this out! @Mamaduka I did look at that documentation prior to trying to alter the block name in my template, but I was simply using the incorrect array key (or, more specifically, I was not going deep enough). I didn't initially understand your comment to mean that I was not using the correct property.

    @t-hamano your example made me realize I was not properly using the metadata key.

    This is what I originally tried:

      $args['template'] = array(
        array( 'core/spacer', array( 
            'name' => 'test'
          )
        ),
      );
    

    Instead, it should have been:

      $args['template'] = array(
        array( 'core/spacer', array( 
            'metadata' => array (
              'name' => 'test'
            )
          )
        ),
      );
    

    I agree that this is primarily a documentation issue. It's not always clear exactly how to set a lot of these properties. In retrospect, I should have created the block in the editor and then looked at the relevant JSON object metadata to determine the proper keys, but it would be nice if that weren't necessary.

    I'll close this issue. Thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions