Skip to content

Instantly share code, notes, and snippets.

@erikyo
Created February 16, 2022 10:15
Show Gist options
  • Save erikyo/27a8513f2e7a21087e53826513804f7a to your computer and use it in GitHub Desktop.
Save erikyo/27a8513f2e7a21087e53826513804f7a to your computer and use it in GitHub Desktop.
A filter for Wordpress oembed Block. Will set Youtube url to "youtube-nocookie.com" and will disable misc related videos (rel=). Enables Vimeo subtitles automatically using the browser language.
<?php
function oembed_utils( $html ) {
// set the default youtube url to youtube-nocookie.com
$html = str_replace("www.youtube.com/embed","www.youtube-nocookie.com/embed", $html);
// remove youtube random related videos
$html = str_replace( "feature=oembed", "feature=oembed&rel=0", $html );
// Set the Vimeo player subtitles accordingly to browser language
if ($lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)) {
$pattern = '/(https\:\/\/player\.vimeo\.com\/video[^"]*)"/';
$html = preg_replace($pattern, "$1&texttrack=" . strtolower( $lang ).'"', $html);
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment