Overview

A click-to-play video embed: a poster image with a play button that is swapped for an autoplaying YouTube or Vimeo iframe when clicked, so no player loads until someone asks for it.


Usage

Paste a Video URL — any of the YouTube forms (youtube.com/watch?v=, youtu.be/, /embed/, /shorts/, /v/) or Vimeo forms (vimeo.com/123, player.vimeo.com/video/123, channel URLs) — and choose a poster under Image Options. The block renders nothing until it has both: a URL it can parse and a poster image. The play icon, its hover color, the background behind the poster and the Image Shade overlay are set under Color Settings; margins, border, radius and shadow per breakpoint as usual.

On the page the poster is a role="button" link. A click builds the provider’s embed iframe with autoplay on, hides the poster (with hidden, so it leaves the accessibility tree too) and moves focus into the player.


Attributes

AttributeTypeDefaultDescription
videoUrlstring—The video’s page URL. Parsed on render by method_parse_video_url() into a provider and id; an unparseable URL renders nothing.
bgImgobject{"id":""}The poster, as the media object MethodBackgroundControls stores (id plus the sizes). Rendered with wp_get_attachment_image() at the size in responsiveSettings.base.bgImgSize (default full) with the method-fit-img class.
linkColorstring—Play icon color (labelled Play Icon).
linkHoverColorstring—Play icon hover color (Play Icon (Hover)).
bgColorstring—Background color behind the poster.
bgGradientstring—Background gradient behind the poster.
bgShadeColorstring—Overlay color on the poster (Image Shade).
bgShadeGradientstring—Overlay gradient on the poster.
responsiveSettingsobject{"base":{"enabled":true},…}Per-tier spacing, border and shadow; see below.

responsiveSettings Structure

Per-tier settings live under responsiveSettings.base, mobile, tablet and wide. A tier is only read while its enabled flag is true; base is always on. The keys this block’s CSS map reads:

  • bgImgSize — base only; the attachment size used for the poster (thumbnail, medium, large, full).
  • margin.top, margin.bottom — on the block wrapper.
  • border, borderRadius — border on the poster link, radius on both the wrapper and the link.
  • shadows — base only (MethodShadowControl), as box-shadow on the wrapper.

Control Sets

ComponentPanelBreakpointsNotes
Block panel: Block OptionsBlock OptionsbaseVideo URL (TextControl).
MethodBackgroundControlsImage OptionsbaseisImg and limited: image selection and size only — no display size, position, parallax or video fallback.
MethodSpacingControlsSpacingbase + mobile / tablet / wideinclude={['margin']}, top and bottom.
MethodBorderControlsBorderbase + mobile / tablet / wideBorder and radius.
MethodShadowControlShadowbaseMulti-layer box shadow.
MethodColorControlsColor Settingsbaseinclude={['linkColor', 'linkHoverColor', 'bgColor', 'bgShadeColor']} with custom labels: Play Icon, Play Icon (Hover), Image Shade.
MethodResponsiveTabsMobile / Tablet / Ultrawidemobile, tablet, wideSpacing and border per tier.
MethodStyleTag—allMirrors $cssargs in the canvas.

Data & Dependencies

  • method_parse_video_url( $url ) (lib/helper-functions.php) — returns [ 'provider' => 'youtube'|'vimeo', 'id' => … ] or null. YouTube ids are the 11-character token after watch?v=, embed/, shorts/, v/ or youtu.be/; Vimeo ids are the numeric id anywhere after vimeo.com/.
  • method_build_embed_url( $provider, $id ) — the iframe URL: https://www.youtube.com/embed/{id} with autoplay=1&rel=0&modestbranding=1&playsinline=1, or https://player.vimeo.com/video/{id} with autoplay=1&title=0&byline=0&portrait=0&dnt=1&playsinline=1. Printed on the wrapper as data-embed-url, with the provider as data-provider.
  • Frontend handler (assets/js/method-fluid-video.js) — binds a click on .method-fluid-video-preview in every .method-fluid-video; on click it appends an iframe (allow="autoplay; encrypted-media; picture-in-picture; fullscreen", a provider-specific title) to .method-fluid-video-player, un-hides it, hides the poster, sets data-active="true" to prevent a second activation, and focuses the player.
  • Styles (assets/scss/global.scss, .method-fluid-video) — the player is aspect-ratio: 16 / 9 with the iframe absolutely filling it; the poster uses the theme’s .method-fit-img-container / .method-fit-img cover treatment.
  • Responsive CSS: method_get_block_responsive_styles() with method_get_responsive_setting() for the image size, collected by method_collect_css() under #method-{id}.

Frontend Rendering

HTML
<div class="wp-block-method-fluid-video method-fluid-video" id="method-68f1b2c3a4d5e" data-embed-url="https://www.youtube.com/embed/dQw4w9WgXcQ?autoplay=1&rel=0&modestbranding=1&playsinline=1" data-provider="youtube">
  <a role="button" class="method-fluid-video-preview">
    <div class="method-invoke-target"><svg …><!-- play icon --></svg></div>
    <div class="method-block-shade"> </div>
    <div class="method-fit-img-container">
      <img class="method-fit-img" src="…poster.jpg" …>
    </div>
  </a>
  <div class="method-fluid-video-player" hidden></div>
</div>

After a click:

HTML
<div class="… method-fluid-video" … data-active="true">
  <a role="button" class="method-fluid-video-preview" hidden>…</a>
  <div class="method-fluid-video-player" tabindex="-1">
    <iframe src="https://www.youtube.com/embed/…?autoplay=1…" class="method-fluid-video__iframe" frameborder="0" allow="autoplay; encrypted-media; picture-in-picture; fullscreen" allowfullscreen title="YouTube video player"></iframe>
  </div>
</div>

Generated CSS (per instance): #method-{id} → radius, margins, shadow; … > .method-fluid-video-preview → text and background color, radius, border; … > .method-block-shade → shade; … > .method-invoke-target → linkColor, and :hover → linkHoverColor.


Filters

This block exposes no PHP filters. The embed parameters (autoplay, related videos off, modest branding, inline playback; Vimeo with title, byline and portrait off and dnt=1) are fixed in method_build_embed_url().


Changelog

VersionDescription
2.0.0-beta14Introduced (ba36676).
2.0.0-beta17Inserter title prefixed, “Method Fluid Video” (c34e9bb).
2.0.0-beta21Recompiled for the reworked multi-layer MethodShadowControl (75910d2).
2.0.0-beta22Retitled “Fluid Video (Method)” and given the method keyword (93e1fcf).