Opened 10 years ago
Closed 10 years ago
#29534 closed enhancement (maybelater)
Support JS API for Youtube Embeds
Reported by: | doytch | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.0 |
Component: | Embeds | Keywords: | |
Focuses: | javascript | Cc: |
Description
The automatic Youtube embeds in 4.0 are cool and standardise a feature that's been implemented over and over again. However, it'd be nice if the embed mechanism could be changed to support Youtube's Javascript API so that plugin's could use the API to add additional features on top of the baked-in embeds. For instance, I'm creating a plugin that allows users to convert timestamps to links that skip to that time in an embedded HTML5 audio or video tag. Youtube support works, but only if the user embeds the iframe manually, specifying an HTTPS URL and enablejsapi=1 in the query params.
For the HTTPS requirement, I suggest converting all Youtube embeds to use HTTPS in the URL. I don't really see a downside to automatically doing this, rather than forcing the user to specify it themselves.
For the enablejsapi requirement, I think it would make sense to include this parameter automatically in the embed link Wordpress generates as well. At the very least, if the user enters a Youtube URL with the parameter set, the embed code should respect that and propagate it into the iframe src. It currently doesn't keep that (any?) parameters set.
This is really a temperature-taking; I've looked at the code and I'm willing and able to create this patch myself, I just want to make sure it'd be well-received before going in and doing it. This seems to be the correct place for this, but let me know if there's a better one.
Change History (3)
#2
@
10 years ago
Thanks for the quick reply. I know Youtube doesn't enable that param automatically, but I was just wondering if it was ever considered to do something like the below (this is code in my plugin) automatically. I'm guessing its a design decision to leave the optional complexity to the plugins, which I understand, but just thought I'd throw it out there. :)
add_filter('oembed_result', 'enable_yt_jsapi'); function enable_yt_jsapi($html, $url, $args) { if (strstr($html, 'youtube.com/embed/')) { $html = str_replace('?feature=oembed', '?feature=oembed&enablejsapi=1', $html); } return $html; }
Thanks for the submission, doytch.
We don't dictate what gets embedded. It is simply whatever embed code YouTube serves up via its oEmbed endpoint. See http://oembed.com, and http://youtube.com/oembed?url=(insert URL to YouTube URL here).