5

How can i add :

class="youtube-player" type="text/html"

to iframe like :

 function Oembed_youtube_no_title($html,$url,$args){
    $url_string = parse_url($url, PHP_URL_QUERY);
    parse_str($url_string, $id);
    if (isset($id['v'])) {
        return '<iframe class="youtube-player" type="text/html" src="https://www.youtube.com/embed/' .$id['v'].'?vq=large&autohide=1&autoplay=1&fs=1&hl=fr&rel=0&loop=1" frameborder="0" allowfullscreen></iframe>';
    }
    return $html;
}
6

You can try this:

add_filter( 'embed_oembed_html', 'custom_youtube_oembed' );
function custom_youtube_oembed( $code ){
    if( stripos( $code, 'youtube.com' ) !== FALSE && stripos( $code, 'iframe' ) !== FALSE )
        $code = str_replace( '<iframe', '<iframe class="youtube-player" type="text/html" ', $code );

    return $code;
}

to target the YouTube oembed HTML output.

When I embed this YouTube link (Kraftwerk) into the post content

http://youtu.be/VXa9tXcMhXQ

I get this HTML output:

<iframe class="youtube-player" type="text/html"  
        width="625" height="469" 
        src="http://www.youtube.com/embed/VXa9tXcMhXQ?feature=oembed" 
        frameborder="0" allowfullscreen></iframe>

with the above filter.

  • Is there no way to check that the oEmbed is a YouTube video other than searching the HTML code (or the second parameter URL, not shown above) for the string youtube.com? Is there some type or other property that can be accessed? – Kimberly W Sep 15 '16 at 14:55
  • I haven't looked into this for a while. I skimmed now through the code and noticed that there is the wp_embed_handler_youtube filter available, but it looks like it could only work on the #https?://(www.)?youtube\.com/(?:v|embed)/([^/]+)#i types of urls. There's also a discussion here about it. Why do you need another approach? Before or after the oembed caching? Maybe this would be better serverd as a new question? @Jamil – birgire Sep 15 '16 at 18:02

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.