I want to add html5=1 in YouTube link. How can I do that? I try something like this:

function add_embed_filter($html, $url, $attr) {
$new = str_replace('oembed', 'oembed&html5=1', $html);
 return $new;

add_filter( 'embed_oembed_html', 'add_embed_filter', 50, 3 );

but in source it look like this: ?feature=oembed&html5=1 :/

function add_embed_filter($html) {
    return '<div class="js-video widescreen">'.str_replace("?feature=oembed", "?html5=1", $html).'</div>';
add_filter( 'embed_oembed_html', 'add_embed_filter', 50, 1);

Of course if WordPress or Youtube change how this url is constructed you will have to adapt your code accordingly, but I tested it, and this will get you there with WordPress 3.8.1. I also did not test how this works for a user who does not support HTML5 and depending on your use case, you may wish to test to ensure that this code will support them.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.