You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Featured image block: The default aspectRatio set in theme.json doesn't work #69769
Thanks for raising this issue! I can confirm that I am able to reproduce the above issue with the default aspectRatio not being applied as expected in the theme.json settings for the Featured Image block. It seems that the block's attributes are not being updated with properties added in the theme.json.
I think I have been able to partially fix this issue, as can be seen The below code uses a switch statement to migrate the theme_json object from version 1 to 2, and then from version 2 to 3. The fall-through mechanism allows it to migrate through versions sequentially.
// Migrate each version in order starting with the current version.switch ( $theme_json['version'] ) {
case1:
$theme_json = self::migrate_v1_to_v2( $theme_json );
// Deliberate fall through. Once migrated to v2, also migrate to v3.case2:
$theme_json = self::migrate_v2_to_v3( $theme_json, $origin );
}
return$theme_json;
Adding a case for version 3 of theme.json for handling migration from version 3 to the next version, ensuring proper handling of all theme versions and preventing missed migrations.
However even after adding this case statement, our original issue is still not fixed, will need some more debugging.
In My understanding, the img element inside the Post Featured Image block is expected to have a height:100% style when the aspectRatio is applied.
However, when the style is applied via the theme.json, the block instance itself doesn't have the aspect ratio attribute applied, so the height style doesn't get applied to the img element.
I think this is the cause. Is this correct?
My guess is that when this support was added, it didn't take into account the scenario where default styles are added via theme.json, so some new ideas or approaches may be needed to solve the issue.
I did some research on this issue, and here are my findings:
When the style is applied via theme.json, the block instance itself doesn’t have the aspect ratio attribute applied, so the height style doesn’t get applied to the <img /> element.
I found that while the aspectRatio property correctly applies to the <figure />, the inner <img /> lacks height: 100%, preventing it from filling the available space. Interestingly, toggling the aspectRatio to any value and back to original adds height: 100%; width: 100%; object-fit: cover to the <img />, though these styles are missing when the image is first uploaded.
The <img /> should always have these styles because:
The original preset includes them by default.
Without an explicit aspectRatio, <figure /> naturally adjusts to the <img /> size (its height and width), so applying height: 100%; width: 100% ensures the image scales properly when an aspect ratio is introduced.
Here's a demo of the above changes:
720p.mov
Caption: Observe the change in aspect ratio
As the previous associated PR is closed, I'd like to open a new PR for this issue.
I've been thinking about this issue again, and I think the root problem is that we are trying to add aspectRatio style via theme.json even though the Post Featured Image block doesn't have aspectRatio block support What the Post Featured Image block has is the aspectRatio attribute, not the aspectRatio block support.
Ideally, we'd like to migrate the aspectRatio attribute in the Post Featured Image block to block support. However, that might be a very complicated task due to backwards compatibility issues.
Ideally, we'd like to migrate the aspectRatio attribute in the Post Featured Image block to block support. However, that might be a very complicated task due to backwards compatibility issues.
Hi, @t-hamano. Could you test #69790 and suggest a way forward? Should we keep the proposed changes in the PR for now? (considering the complexity due to backward compatibility), or take the more challenging approach?
Edit: I believe it's the same for the image block as well; it uses the aspectRatio attribute and not the block support and migrating that might also come with certain backwards compatibility issues.
Could you test #69790 and suggest a way forward? Should we keep the proposed changes in the PR for now? (considering the complexity due to backward compatibility), or take the more challenging approach?
Personally, it's difficult to say for sure whether this issue itself is a bug, because we're trying to apply styles via theme.json that the block doesn't support in the first place.
It's weird that the block itself doesn't have the block support, but it tries to take into account styles provided by theme.json.
I would like to propose to stop #69790 and migrate to block support, but I have not yet been able to clarify the issues that need to be resolved 😅
Ideally, aspectRatio should be implemented with block support.
"dimensions": {
"aspectRatio": true
},
This will allow customization from Styles in the site editor.
However, even if this is achieved, changes like #69790 are required.
It may be better to consider the aspectRatio of the image block and post eyecatcher block separately from the transition to block support.
Activity
yogeshbhutkar commentedon Apr 1, 2025
Thanks for the issue!
I can replicate this on the
Imageblock as well.Sourav61 commentedon Apr 1, 2025
Thanks for raising this issue! I can confirm that I am able to reproduce the above issue with the default aspectRatio not being applied as expected in the theme.json settings for the Featured Image block. It seems that the block's attributes are not being updated with properties added in the theme.json.
I think I have been able to partially fix this issue, as can be seen The below code uses a switch statement to migrate the theme_json object from version 1 to 2, and then from version 2 to 3. The fall-through mechanism allows it to migrate through versions sequentially.
lib/class-wp-theme-json-schema-gutenberg.php
Adding a case for version 3 of theme.json for handling migration from version 3 to the next version, ensuring proper handling of all theme versions and preventing missed migrations.
However even after adding this case statement, our original issue is still not fixed, will need some more debugging.
t-hamano commentedon Apr 1, 2025
@Sourav61 theme.json version 4 doesn't exist yet, so we can't migrate from version 3 to version 4.
First, let's find out why the problem occurs and identify the root cause.
t-hamano commentedon Apr 1, 2025
In My understanding, the
imgelement inside the Post Featured Image block is expected to have aheight:100%style when theaspectRatiois applied.However, when the style is applied via the theme.json, the block instance itself doesn't have the aspect ratio attribute applied, so the height style doesn't get applied to the
imgelement.I think this is the cause. Is this correct?
My guess is that when this support was added, it didn't take into account the scenario where default styles are added via theme.json, so some new ideas or approaches may be needed to solve the issue.
yogeshbhutkar commentedon Apr 2, 2025
I did some research on this issue, and here are my findings:
I found that while the
aspectRatioproperty correctly applies to the<figure />, the inner<img />lacksheight: 100%, preventing it from filling the available space. Interestingly, toggling theaspectRatioto any value and back tooriginaladdsheight: 100%; width: 100%; object-fit: coverto the<img />, though these styles are missing when the image is first uploaded.The
<img />should always have these styles because:originalpreset includes them by default.aspectRatio,<figure />naturally adjusts to the<img />size (its height and width), so applyingheight: 100%; width: 100%ensures the image scales properly when an aspect ratio is introduced.Here's a demo of the above changes:
720p.mov
Caption: Observe the change in aspect ratio
As the previous associated PR is closed, I'd like to open a new PR for this issue.
t-hamano commentedon Apr 2, 2025
I've been thinking about this issue again, and I think the root problem is that we are trying to add aspectRatio style via theme.json even though the Post Featured Image block doesn't have aspectRatio block support What the Post Featured Image block has is the aspectRatio attribute, not the aspectRatio block support.
Ideally, we'd like to migrate the aspectRatio attribute in the Post Featured Image block to block support. However, that might be a very complicated task due to backwards compatibility issues.
yogeshbhutkar commentedon Apr 2, 2025
Hi, @t-hamano. Could you test #69790 and suggest a way forward? Should we keep the proposed changes in the PR for now? (considering the complexity due to backward compatibility), or take the more challenging approach?
Edit: I believe it's the same for the
imageblock as well; it uses theaspectRatioattribute and not the block support and migrating that might also come with certain backwards compatibility issues.t-hamano commentedon Apr 2, 2025
Personally, it's difficult to say for sure whether this issue itself is a bug, because we're trying to apply styles via theme.json that the block doesn't support in the first place.
It's weird that the block itself doesn't have the block support, but it tries to take into account styles provided by theme.json.
I would like to propose to stop #69790 and migrate to block support, but I have not yet been able to clarify the issues that need to be resolved 😅
shimotmk commentedon Apr 2, 2025
Ideally, aspectRatio should be implemented with block support.
This will allow customization from Styles in the site editor.
However, even if this is achieved, changes like #69790 are required.
It may be better to consider the aspectRatio of the image block and post eyecatcher block separately from the transition to block support.
Related:#56897 (comment)
shimotmk commentedon Nov 3, 2025
This is also related to these issues.