Default block alignment class is not in get_block_wrapper_attributes
warudin opened this issue · 4 comments
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
- Configure a block to have a specific alignment (i.e. 'full') by adding it as a default value in attributes.align in block.json;
- Configure and create a PHP render template file in block.json;
- Use
get_block_wrapper_attributes()
to output the classes in the wrapper div; - Add the block to the editor and leave the default alignment configured, save the editor;
- 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
I trapped on same situation as @warudin says. However, it may be fixed in upcoming release. In the meantime, I find out a temprary solution. My render.php is like
<div <?php echo get_block_wrapper_attributes(
array(
'class' => 'align' . $attributes['align']
) ); ?>>
<?php
echo $content;
?>
</div>
This is exactly the same issue that I run into. I use ACF to be able to use render.php files for rendering my HTML. My block.json contains this:
"attributes": {"align": { "type": "string", "default": "left" }, }
But when I use get_block_wrapper_attributes(), the class alignleft is not added to the classes by default.
I hope this issue is fixed soon. The workaround I have now is to use the filter render_block_data() and add these default settings by default from the .json file if they are not present. That works, but is not the best solution...