9 years later in 2025
add_filter('oembed_result', function ($html, $url, $args) {
if (strstr($html, 'youtube.com/embed/')) {
$html = str_replace('?feature=oembed', '?feature=oembed&enablejsapi=1', $html);
}
return $html;
}, 10, 3);
works for just youtube videos,
you can then get the iframe like
const iframe = document.querySelectorAll("iframe");
if (iframe.contentWindow && iframe.src.startsWith("https://www.youtube.com")) {
iframe.contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}',"*" );
}