Changing the default wordpress youtube embeded video dimensions

I just upgraded to WordPress 3.5, and one cool feature seems to be that if you copy a Youtube URL directly from the browser and paste into a singles post, the video automatically embeds!

However, I’m having trouble figuring out why the following (pasted in a standard post) doesn’t work to adjust the dimensions of the embed:

Read More

I searched around Stackoverflow, and it seems like people were saying that you could adjust the dimensions in Settings > Media, but that feature has been deprecated. Another person blogging at http://shailan.com/2154/change-wordpress-default-embed-size-using-filters/ suggested adding a filter

function mycustom_embed_defaults($embed_size){
     if( is_single() ){ // If displaying a single post
        $embed_size['width'] = 586; // Adjust values to your needs
    $embed_size['height'] = 500; 
}

return $embed_size; // Return new size
}

add_filter('embed_defaults', 'mycustom_embed_defaults'); 

… but after adding this to functions.php and changing the width and height to 100 both, I didn’t see a difference in the post preview.

Right now I’m still trying to figure out how to reset the default dimensions of a youtube URL pasted into a WordPress post without resorting to pasting in the entire iframe, i.e.

<iframe width="560" height="315" src="http://www.youtube.com/embed/IjoxX5dXM8g" frameborder="0" allowfullscreen></iframe>

Related posts

Leave a Reply

1 comment

  1. Try this:

    add_filter( 'embed_defaults', 'change_embed_size' );
    
    function change_embed_size() {
        // Adjust values
        return array('width' => 100, 'height' => 100);
    }