-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the wp-has-aspect-ratio
class from block embeds
#4813
Conversation
I can see this change between 8.1 and 8.2: It came from this PR: https://github.com/WordPress/gutenberg/pull/21599/files?diff=split&w=1 |
So what was formerly: .wp-embed-responsive .wp-block-embed.wp-embed-aspect-16-9 .wp-block-embed__wrapper::before {
padding-top: 56.25%;
} Is now: .wp-embed-responsive .wp-embed-aspect-16-9 .wp-block-embed__wrapper:before {
padding-top: 56.25%;
} |
And this is the result when the |
$class | ||
) | ||
|
||
$classes = preg_replace_callback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As opposed to using preg_replace_callback()
would it make more sense to use array_filter()
? So perhaps this would be marginally better:
$classes = array_filter(
$classes,
static function ( $class ) use ( &$responsive_width, &$responsive_height ) {
if ( preg_match( '/^wp-embed-aspect-(?P<width>\d+)-(?P<height>\d+)$/', $class, $matches ) ) {
$responsive_width = $matches['width'];
$responsive_height = $matches['height'];
return false;
}
return 'wp-has-aspect-ratio' !== $class;
}
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For that matter, this could also be used instead of the array_diff()
above as well. (Now updated the above.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in ae78190.
Co-authored-by: Weston Ruter <westonruter@google.com>
I've confirmed that an embed looks properly in WP 5.4 both when Gutenberg 8.3 is active and when it is inactive. |
Summary
As of Gutenberg 8.2, when the
wp-has-aspect-ratio
class is set on an embed block, it adds a large gap to the top of the embed. This breaks the visual parity of the AMP page when compared to its non-AMP counterpart. For example:The
wp-has-aspect-ratio
class is not needed in the AMP context because the responsive layout of the embed will be handled natively. When the class is removed, visual parity is restored:Fixes #4810
Related: #1683
Checklist