method_build_embed_url()
method_build_embed_url( $provider, $id )
The autoplaying player URL for a YouTube or Vimeo video id.
Description
Builds the iframe src the Fluid Video block loads when its poster is clicked. YouTube ids become https://www.youtube.com/embed/{id} with autoplay=1, rel=0 (no related videos from other channels), modestbranding=1 and playsinline=1 (inline playback on iOS). Vimeo ids become https://player.vimeo.com/video/{id} with autoplay=1, title=0, byline=0, portrait=0, dnt=1 and playsinline=1. The arguments are added with add_query_arg().
Parameters
$provider (string) : youtube or vimeo — what method_parse_video_url() returns.
$id (string) :
The video id.
Return
(string) The embed URL, or '' for any other provider.
Source
File: lib/helper-functions.php
Usage
PHP
echo method_build_embed_url( 'vimeo', '76979871' );
// https://player.vimeo.com/video/76979871?autoplay=1&title=0&byline=0&portrait=0&dnt=1&playsinline=1
Notes
- Autoplay with sound is subject to the browser’s autoplay policy; because the Fluid Video block builds the iframe inside a click handler, the user gesture normally allows it. A
mute/mutedargument is left commented out in the source for sites that want guaranteed autoplay. - The result is printed by the block as
data-embed-urlafteresc_url().
Changelog
| Version | Description |
|---|---|
| 2.0.0-beta14 | Introduced, with the Fluid Video block (ba36676). |