I was wondering if it's possible to use oEmbed that is built into the core of WP to display video embeds but somehow remove the height and width attritbutes in the output? I know the functions exist in media.php but I don't want to mess with the core.

The reason I ask is that we're developing a theme for a client which using a fluid grid framework and any image/video with specified height and width attributes means they don't scale with the grid in smaller viewports - or there may be a way to make this work?

Any help would be much appreciated


1 Answer 1


The output of the oEmbed call is filtered through oembed_result and then cached in the database. Every time the content is displayed, the output is filtered again through embed_oembed_html. So you can add a filter in either of these places that checks for width and height attributes and removes them. Of course, since the code comes from the embed sources, you can't always be sure what the formatting will look like. The second argument to both filters is the embed URL, you can check that to differentiate your handling ("if it's from YouTube do this, if it's from Flickr do that, ...").

  • Thanks Jan, so would something along the lines of this be correct?code function strip_attributes($oembvideo) { $patterns = array(); $replacements = array(); $patterns[] = '<iframe height=""'; $patterns[] = '<iframe width=""'; $replacements[] = '<iframe height=""'; $replacements[] = '<iframe width=""'; return preg_replace($patterns, $replacements, $oembvideo); return $oembvideo; } add_filter('embed_oembed_html', 'stripattributes');
    – Mark-Fublo
    Feb 13, 2011 at 19:20
  • @Mark-Fublo: That would be the idea, yes. Of course, not every video is returned in an iframe, and maybe there are other parameters that define the size of the player. You'll have to try it and see what works. Post it back as an answer, it could be useful for others!
    – Jan Fabry
    Feb 13, 2011 at 19:50
  • Thanks. Yes, the client is only using Vimeo in this instance, so I'll see what I can work out and see if I can get it working
    – Mark-Fublo
    Feb 13, 2011 at 22:21
  • I can't seem to paste the code from here wp-snippets.com/adjust-vimeo-auto-embed-size into this comment, too big..
    – Mark-Fublo
    Feb 13, 2011 at 22:41
  • Anyway, I can edit the height and width to output as nothing. Though it displays the video at the incorrect size. Realistically a solution to have full width video at all sizes of the viewport is what I am after - If it can be done at all?
    – Mark-Fublo
    Feb 13, 2011 at 22:42

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.