gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Embed blocks: Full-width in the block editor, content-fit on the live site

Open zaguiini opened this issue 4 years ago • 4 comments

Description

The Soundcloud embed displays wide in the block editor but has a fixed width of 500px while browsing the live site. The same thing happens with the Kindle embed block.

Step-by-step reproduction instructions

  1. Open FSE;
  2. Insert Soundcloud or Kindle embed block;
  3. Save the page.

Verify that it's inconsistent between the block editor and the live site.

Screenshots, screen recording, code snippet

Editor Live site
image image
image image

Environment info

  • WordPress 5.8.2;
  • Gutenberg 12.1.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

zaguiini avatar Dec 10 '21 15:12 zaguiini

Is there some kind of workaround / easy fix for this?

aleksblendwerk avatar Feb 01 '22 23:02 aleksblendwerk

@aleksblendwerk

you can add a style to override it

figure.is-provider-soundcloud.wp-block-embed-soundcloud iframe { width: 100%; }

djossia avatar Jun 13 '22 23:06 djossia

Confirmed this is still present in testing in WP 6.3

jordesign avatar Sep 14 '23 04:09 jordesign

I've been digging into this one and would love to work on it. I wanted to share what I found and check the direction before opening a PR.

I can still reproduce it on trunk (WP 7.1, Twenty Twenty-Five). The SoundCloud player is 600px wide in the editor and 500px on the front end, and neither fills the block. Kindle does the same thing.

From what I can tell, the root cause is in core rather than in the embed block itself. The editor preview and the front end ask the provider for different widths:

  • Front end: WP_Embed uses wp_embed_defaults(), which is $content_width or 500px.
  • Editor: the block calls /oembed/1.0/proxy with just the URL, and that route forces maxwidth to oembed_default_width (600px).

Most video providers hide this because the responsive aspect-ratio classes stretch them to fill the block anyway. Providers whose ratio doesn't match one of the known ratios keep the fixed width they were given, so they show the mismatch. That's SoundCloud (500×400), Kindle (500×550) and Scribd (500×750). Spotify and Mixcloud return width="100%", so they're fine.

Interestingly, WP_oEmbed::fetch() already falls back to wp_embed_defaults() when no width is passed. It's only the proxy route's default that overrides it. So I see two possible directions:

  1. Fix it in core (my preference): when the proxy request doesn't include a maxwidth, default to wp_embed_defaults( $url )['width'] instead of 600. The editor and front end would then always request the same size, for every provider. It's a small change in WP_oEmbed_Controller, which would mean a Trac ticket and a wordpress-develop PR.
  2. Handle it in Gutenberg: add CSS so iframes from these specific providers fill the block, in both the editor sandbox and on the front end. I have this working locally, but it needs a hardcoded provider list. Provider slugs also drift (Kindle now reports itself as amazon, not amazon-kindle), so it feels more like a patch than a fix.

Mustafabharmal avatar Oct 13 '26 13:10 Mustafabharmal