-
Notifications
You must be signed in to change notification settings - Fork 279
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
.first-block-align-wide body class not showing with media-text block. #327
Comments
Thanks, @jamiemitchell. The issue is caused by WordPress Core omitting the align attribute if the media-text block uses the default 'wide' alignment. If you don't set any alignment (defaults to wide), the media block has a blank 'align' attribute:
Which results in this body class at present in Genesis Sample:
If you click the 'wide' alignment, the media block has these attributes (align attribute is missing):
…which results in no class at all. If you set alignment to 'full', WP core then outputs the expected alignment attribute:
So the correct body class of I will report this as a bug in the Gutenberg repo. WordPress should output the alignment of the block, whether it's the default or manually selected. For now, you can fix it by amending Replace this code near the end of the function: if ( isset( $blocks[0]['attrs']['align'] ) ) {
$classes[] = 'first-block-align-' . $blocks[0]['attrs']['align'];
} With this: if ( isset( $blocks[0]['attrs']['align'] ) && $blocks[0]['attrs']['align'] ) {
$classes[] = 'first-block-align-' . $blocks[0]['attrs']['align'];
}
// Workaround to add -align-wide class for media-text block.
// See https://github.com/studiopress/genesis-sample/issues/327.
if ( 'core/media-text' === $blocks[0]['blockName'] ) {
if ( ! isset( $blocks[0]['attrs']['align'] ) || ! $blocks[0]['attrs']['align'] ) {
$classes[] = 'first-block-align-wide';
}
} You should then get the |
Found an existing issue in Gutenberg at WordPress/gutenberg#16365. Noting it may affect other blocks that default to wide too. The if statement above ( |
Nice job in tracing that bug @nickcernis That code worked a treat, will do the job for now. And thanks for the fast and detailed reply. |
I'm not getting the '.first-block-align-wide' body class added when using the 'media-text block' set to 'alignwide', but the '-align-wide' body class does show with other blocks set to alignwide
'-align-full' gets added just fine with the 'media-text block'.
The text was updated successfully, but these errors were encountered: