YouTube oEmbed and privacy-enhanced mode
When you´re embed a youtube video in an iframe, you can enable the privacy-enhanced mode, so YouTube doesn´t store information about your web page visitors until they play the video.
I've tried to embed a video via oEmbed and the URL
but it didn't work. Is there a chance to implement a privacy-friendly solution with oEmbed?
EDIT I found this proposal and tried to customize it and it seems to work, but there is one thing that is not optimal. You can´t use the defined $content_width, because this solution needs a declaration of the height, too. Any ideas to this approach or do you have another?
wp_embed_register_handler( 'ytnocookie', '#https?://www\.youtube\-nocookie\.com/embed/([a-z0-9\-_]+)#i', 'wp_embed_handler_ytnocookie' );
wp_embed_register_handler( 'ytnormal', '#https?://www\.youtube\.com/watch\?v=([a-z0-9\-_]+)#i', 'wp_embed_handler_ytnocookie' );
wp_embed_register_handler( 'ytnormal2', '#https?://www\.youtube\.com/watch\?feature=player_embeddedamp;v=([a-z0-9\-_]+)#i', 'wp_embed_handler_ytnocookie' );
function wp_embed_handler_ytnocookie( $matches, $attr, $url, $rawattr ) {
global $defaultoptions;
$defaultoptions['yt-content-width'] = '680';
$defaultoptions['yt-content-height'] = '510';
$defaultoptions['yt-norel'] = 1;
$relvideo = '';
if ($defaultoptions['yt-norel']==1) {
$relvideo = '?rel=0';
}
$embed = sprintf(
'iframe src="https://www.youtube-nocookie.com/embed/%2$s%5$s" width="%3$spx" height="%4$spx" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"/iframepa href="https://www.youtube.com/watch?v=%2$s" title="View video on YouTube"View video on YouTube/a/p',
get_template_directory_uri(),
esc_attr($matches[1]),
$defaultoptions['yt-content-width'],
$defaultoptions['yt-content-height'],
$relvideo
);
return apply_filters( 'embed_ytnocookie', $embed, $matches, $attr, $url, $rawattr );
}