Skip to content

Media & Text: Keep image size and URL in sync when selecting media - #84698

Open
Mustafabharmal wants to merge 2 commits into
WordPress:trunkfrom
Mustafabharmal:fix/media-text-default-image-size
Open

Mustafabharmal wants to merge 2 commits into
WordPress:trunkfrom
Mustafabharmal:fix/media-text-default-image-size

Conversation

@Mustafabharmal

@Mustafabharmal Mustafabharmal commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What?

Fixes #38520.

When an image is selected in the Media & Text block, the image URL, the Resolution control and the size-* class now always match.

Why?

When an image was selected, the block always used the "large" URL but never stored mediaSizeSlug. The Resolution control and the saved size-* class fall back to full, so the sidebar showed "Full Size" while the front end rendered the large image. To get the real full-size image, users had to pick another size and then switch back. A mediaSizeSlug already set on the block (for example in a pattern) was also ignored, and the site's default image size setting was not respected.

How?

In attributesFromMedia(), the size is now chosen in this order, the same way the Image and Cover blocks do it:

  1. The block's current mediaSizeSlug, if the image has that size.
  2. The imageDefaultSize editor setting (large by default).
  3. full.

The image URL comes from that size, and the size is stored in mediaSizeSlug. Videos are unaffected. save output is unchanged, so no deprecation is needed, and the default stays large, so performance is the same.

Testing Instructions

  1. Upload an image wider than the "Large" size (default 1024px), for example 2400×1600.
  2. Create a post, insert a Media & Text block and select that image.
  3. Check that Resolution in the block sidebar shows "Large". In the Code editor, check for "mediaSizeSlug":"large", an image src ending in -1024x… and the class size-large.
  4. Save and view the post. Confirm the front end shows the same large image with size-large.
  5. Change Resolution to "Full Size" and confirm the full image and the size-full class are used.
  6. Replace the image with another large one and confirm "Full Size" is kept.
  7. In the Code editor, paste <!-- wp:media-text {"mediaSizeSlug":"thumbnail"} --><div class="wp-block-media-text is-stacked-on-mobile"><figure class="wp-block-media-text__media"></figure><div class="wp-block-media-text__content"></div></div><!-- /wp:media-text -->, select an image, and confirm the thumbnail is used.
  8. Select an image smaller than "Large" and confirm "Full Size" is shown and used.

Use of AI Tools

I used Claude Code to look into the cause and draft the change and this description. I reviewed and tested the change myself.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @hazardawareness, @DDadam21, @viktory-tori.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: hazardawareness, DDadam21, viktory-tori.

Co-authored-by: Mustafabharmal <mustafabharmal@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: MatzeKitt <kittmedia@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@Mustafabharmal
Mustafabharmal marked this pull request as ready for review October 15, 2026 17:29

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default image size ignored in Media Text block

1 participant