Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
    
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! –  mathiregister Apr 11 '11 at 6:34
    
this is the solution: add_filter('embed_oembed_html', 'add_video_embed_note', 10, 3); –  mathiregister Apr 11 '11 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 Apr 11 '11 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? –  Adam Christianson Jul 1 '13 at 16:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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