-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Image Block Alignments broken on themes using theme.json #40323
Comments
Hi @philhoyt, while not ideal, this is expected behavior in block themes. The image |
This is not okay. To explain to a client they would need to wrap their image in a group to accommodate alignments is unacceptable. Are posts imported from previous themes not taken into account for backward compatibility? The block already wraps the image in a div as explained in previous iterations of the block editor. Your "expected behavior in block themes" results in "not ideal" behavior in the default FSE theme. |
Looks to be reverted... weird |
Hey guys, any updates on this issue? Without it everything breaks and adding wrap the image inside a group is not great at all because people will have to edit all their posts manually... |
I spent hours trying to figure out why some of my client sites get the div wrapper around alignright and alignleft image blocks and others don't. Even Twenty Twenty-One has the wrapper, but switching same site to Twenty Twenty-Two removed the wrapping div. I finally figured out it was the presence of the theme.json file in the theme. The extra wrapping div allows me to align the floated images with the other margin-left, margin-right: auto content on pages. Otherwise, there is no container to add the margin: auto to, with a float on the figure so paragraphs can wrap around it. The Twenty Twenty-Two theme floats alignleft image blocks way off to the side. Is there any chance the wrapping div can be added back to image blocks aligned left or right? |
So this is bug that won't be fixed, which will break thousands of websites if they update to an FSE theme. |
Adding the following to a css-file (style.css) creates a workaround for this issue. It won't work in the editor, only in the frontend.
|
This is clearly unacceptable behavior from the image block. Please fix asap. |
Here is my solution: wrapping the image block in a div. Works in my current theme. Frontend:
Backend (enqueue script in backend with admin_enqueue_scripts)
This took me a few hours to figure out and may not be optimized for your project, I wish we didn't have to struggle as much with the new editor. Image blocks should never have behaved that way. |
@audunmb 👍 thank you - solution works. but - might - need to consider
@delorimier there's an |
Description
Image blocks when rendered on themes using theme.json output as followed
Without a div container resulting in the following

This is easily tested with themes like Twenty Twenty-Two, but not limited to FSE themes.
Image blocks on non theme.json themes render as followed
resulting in the desired alignment visually

This was tested using WordPress 5.9.3
with and without Gutenberg 12.9.0
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
No response
Environment info
This was tested using WordPress 5.9.3
with and without Gutenberg 12.9.0
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
The text was updated successfully, but these errors were encountered: