Opened 6 years ago
Last modified 4 months ago
#31920 assigned enhancement
oEmbed: Support YouTube timestamps as hashes
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Embeds | Keywords: | needs-patch needs-unit-tests good-first-bug |
Focuses: | Cc: |
Description
YouTube can provide timestamps as a hash, which doesn't get properly processed by the oEmbed endpoint: https://www.youtube.com/watch?v=8A6q6eGM_Aw#t=8m30s
Converting the hash to a proper query argument produces the expected behavior: https://www.youtube.com/watch?v=8A6q6eGM_Aw&t=8m30s
Although it's a pain to maintain compatibility shims, including in core would reduce user confusion around oEmbed.
/** * Support YouTube timestamp as hash (e.g. https://www.youtube.com/watch?v=8A6q6eGM_Aw#t=8m30s) * by converting the hash to a query arg */ add_filter( 'oembed_fetch_url', function( $provider, $url, $args ) { if ( false === stripos( $provider, 'www.youtube.com/oembed' ) || false === stripos( $url, '#t=' ) ) { return $provider; } $url = str_replace( '#t=', '&t=', $url ); $provider = add_query_arg( 'url', rawurlencode( $url ), $provider ); return $provider; }, 10, 3 );
Change History (8)
#2
@
6 years ago
Perhaps other providers support this as well. I know that Vimeo supports that hash, but I think not the query param for embeds.
#4
@
5 years ago
- Keywords needs-unit-tests added
- Owner set to peterwilsoncc
- Status changed from new to accepted
This ticket was mentioned in Slack in #core by ocean90. View the logs.
5 years ago
#6
@
5 years ago
Edge cases need to be dealt with, the first to come to mind is campaign tags and a time stamp:
https://www.youtube.com/watch?v=btPJPFnesV4#utm_source=cats&utm_medium=wordpress&utm_campaign=kittens&t=3s
I'll keep on the milestone for now as I'm working through a patch with a (hopefully soon) first contributor.
Agreed. Helpers are annoying, but fixing this issue is worth it.