Linux 软件免费装

Responsive oEmbed

开发者 palasthotel
greatestview
更新时间 2026年8月3日 20:00
捐献地址: 去捐款
PHP版本: 4.0 及以上
WordPress版本: 5.1
版权: GNU General Public License v3
版权网址: 版权信息

标签

responsive vimeo youtube soundcloud oembed iframe aspect ratio

下载

1.3 1.2 1.4 1.4.1 1.1 1.4.2

详情介绍:

This plugin is retired and no longer maintained. Please deactivate and remove it. WordPress solves this itself since version 5.0. A theme that declares add_theme_support( 'responsive-embeds' ) — which every block theme does automatically — gets responsive embeds from core for content written with the block editor. Nothing needs to be installed for that. Worse than being redundant, this plugin conflicts with it. Core wraps an embed block in .wp-block-embed__wrapper and sets the aspect ratio there; this plugin adds a second wrapper with a second aspect ratio inside it. The result is a mis-sized embed. That has been the case since WordPress 5.0 and cannot be fixed from where this plugin hooks, because WP_Embed::autoembed runs on the_content at priority 8, before do_blocks at priority 9 — the filter never sees whether it is inside a block. What to do instead If your site uses the block editor and a block theme, remove the plugin. Core already handles it. If you use a classic theme, add add_theme_support( 'responsive-embeds' ) to it and use embed blocks. Core does not cover embeds in classic content or wp_oembed_get() calls in a template. If you rely on those, this is what the plugin did, in a form you can put into your own theme: `add_filter( 'embed_oembed_html', 'my_responsive_embed', 99 ); add_filter( 'oembed_result', 'my_responsive_embed', 99 ); function my_responsive_embed( string $html ): string { // WordPress post embeds size themselves via wp-embed.js. if ( str_contains( $html, 'data-secret=' ) ) { return $html; } if ( ! preg_match( '/<(?:iframe|object|embed)\s[^>]*>/i', $html, $tag ) ) { return $html; } // The value has to end right after the digits, so width="100%" is skipped - // a percentage carries no aspect ratio. if ( ! preg_match( '/\bwidth=(["\']?)(\d+)\1[\s>]/i', $tag[0], $w ) || ! preg_match( '/\bheight=(["\']?)(\d+)\1[\s>]/i', $tag[0], $h ) ) { return $html; } return sprintf( ' %s', (int) $w[2], (int) $h[2], $html ); }` With this CSS: .my-responsive-embed { width: 100%; } .my-responsive-embed > iframe, .my-responsive-embed > object, .my-responsive-embed > embed { width: 100%; height: 100%; } This uses the aspect-ratio CSS property instead of the padding-top trick the plugin used, and it skips percentage widths — the plugin did not, which is why SoundCloud embeds came out far too tall. What the plugin did It used minimal CSS rules and a wrapping HTML element to maintain the aspect ratio of oEmbed elements with a fixed aspect ratio (e. g. YouTube, Vimeo or Soundcloud). Unlike other plugins, this plugin does not use any JavaScript! The aspect ratio is calculated from the (iframe, object or embed) HTML tag width and height attributes. An aspect ratio will only be applied, if both width AND height attributes are given by the oEmbed element and if there is no data-secret attribut set (because those are handled via wp-embed.js). Some oEmbeds have no width or height attributes set, because they calculate their dimension via JavaScript. In those cases this plugin has no effect. You can find a list of all oEmbed sites supported by WordPress here.

安装:

Please do not install this plugin any more — it is retired. See the description for what to use instead. To remove it: deactivate it under Plugins, then delete it. The plugin stores no options and creates no database tables, so nothing is left behind. Embeds written with the block editor keep working, because core supplies the CSS for them.

升级注意事项:

1.4.2 This plugin is retired. WordPress has handled responsive embeds itself since 5.0, and this plugin conflicts with that mechanism in the block editor. Please deactivate and remove it; the description explains what to use instead.

更新日志:

1.4.2 1.4.1 1.4 1.3 1.2 1.1 1.0