Skip to content

Default block alignment class is not in get_block_wrapper_attributes #50027

@warudin

Description

@warudin

Description

I created a block, the settings are below in the block.json.

The block should have a full width alignment by default (mentioned here in the documentation: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#align)

This works good in the editor. But in my render file, the get_block_wrapper_attributes() function is not outputting the align class.

The align class is only returned when I configure another block width then the one that’s in the attributes (so ‘none’ or ‘wide’). The default alignment is never returned, even after toggling another one and going back to the default alignment.

block.json:
{
	...
	"attributes": {
		"align": {
			"type": "string",
			"default": "full"
		}
		...
	},
	"supports": {
		"html": false,
		"align": [
			"wide",
			"full"
		],
		...
	},
	...
}

Step-by-step reproduction instructions

  1. Configure a block to have a specific alignment (i.e. 'full') by adding it as a default value in attributes.align in block.json;
  2. Configure and create a PHP render template file in block.json;
  3. Use get_block_wrapper_attributes() to output the classes in the wrapper div;
  4. Add the block to the editor and leave the default alignment configured, save the editor;
  5. Check the classes being output in the front-end, the configured alignment will not be in the list that's being returned by get_block_wrapper_attributes().

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.2, Gutenberg 15.6.2, custom template (full site editing boilerplate)

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

Labels

[Package] Blocks/packages/blocks[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended[Type] WP Core TicketRequires an upstream change from WordPress. Core Trac ticket should be linked.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions