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!
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), andembed_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.