My posts have YouTube embedded videos in the form of:

<object width="600" height="400" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/zN9mdItmoBs&amp;vq=hd720" /><embed width="600" height="400" type="application/x-shockwave-flash" src="http://www.youtube.com/v/zN9mdItmoBs&amp;vq=hd720" /></object>

How do I wrap a <div> around it?

I've tried adding the following to the functions.php file:

add_filter('embed_oembed_html', 'my_embed_oembed_html', 99, 4);
function my_embed_oembed_html($html, $url, $attr, $post_id) {
  return '<div id="video">' . $html . '</div>';

It doesn't work. What do I do?

1 Answer 1


I'm not sure why that's not working except maybe you need to put the returned stuff in a variable? This is what works for me when I put it in my functions.php file:

add_filter( 'embed_oembed_html', 'tdd_oembed_filter', 10, 4 ) ; 
function tdd_oembed_filter($html, $url, $attr, $post_ID) {
    $return = '<figure class="video-container">'.$html.'</figure>';
    return $return;
  • It still doesn't work. I'm using Twenty Thirteen if that helps. Oct 19, 2013 at 17:19
  • Michelle's code and yours works for me on WP 3.6 with no plugins installed on TwentyThirteen and any other default theme.
    – Wyck
    Oct 19, 2013 at 18:11
  • I'm also using WP 3.6 and no plugins; it's a fresh install. All I do is edit the functions file right? I'm not sure what the problem is. Oct 19, 2013 at 22:25
  • How are you embedding the object? This may only work for the oembed method where you put the plaintext YouTube URL in the content on its own line and it auto-converts to an embedded object...?
    – Michelle
    Oct 19, 2013 at 23:31
  • I put the embed code I posted above in a post under Text. Oct 19, 2013 at 23:39

Your Answer

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

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