4

hey guys, when posting a youtube video link in the backend (in a post or a page) wordpress is automatically creating the embed code for me.

Is it possible to add a filter to that? I'd love to change the width and height of all embedded videos to 100%?

e.g.

<object width="100%" height="100%">
<param name="movie" value="http://www.youtube.com/v/rBa5qp9sUOY?version=3">
<param name="allowFullScreen" value="true">
<param name="allowscriptaccess" value="always">
<embed src="http://www.youtube.com/v/rBa5qp9sUOY?version=3" type="application/x-shockwave-flash" width="100%" height="100%" allowscriptaccess="always" allowfullscreen="true">
</object>`

Any idea how to solve this?

edit: Or is it at least possible to add a classname to the object tag so I can use javascript to influence with and height of the embedded video?

update: Thank you I tried the following piece of code but it doesn't work?

add_filter('oembed_result','oembed_result', 10, 3);

function oembed_result($html, $url, $args) {

    // $args includes custom argument
    // modify $html as you need

    //return $html; 
}

if return $html is a comment no youtube video should appear right, however it does!

1 Answer 1

11

Yes, there is a filter for Oembeds. Two (or even more) in fact: oembed_result will be called before it is put in the cache (so only once per external embed), and embed_oembed_html after the cache (so every time the item is displayed). If you only need to modify it once, oembed_result is probably your friend. The second parameter is the $url, so check whether it comes from Youtube before you do something.

4
  • 1
    thank you, however I can't seem to get it working! I updated my question so you can see what code I've tried. The filter doesn't seem to influence my youtube vids! Commented Apr 11, 2011 at 6:34
  • 1
    this is the solution: add_filter('embed_oembed_html', 'add_video_embed_note', 10, 3); Commented Apr 11, 2011 at 7:17
  • @mathiregister: If oembed_result does not work it is probably because that video is already in the cache. embed_oembed_html will always be executed - which is more flexible, but also a bigger burden on your server.
    – Jan Fabry
    Commented Apr 11, 2011 at 7:25
  • I am also trying to use the oembed_result filter and no matter what I seem to do, it doesn't appear to fire. I've also tried the embed_oembed_html filter and that doesn't seem to work either. Has anyone found a solution? Commented Jul 1, 2013 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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