add_filter to youtube embeds?

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="https://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!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x