Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: [embed width="20" height="106"]https://www.youtube.com/watch?v=IjoxX5dXM8g[/embed]

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>
like image 682
LNA Avatar asked Dec 15 '22 09:12

LNA


1 Answers

Try this:

add_filter( 'embed_defaults', 'change_embed_size' );

function change_embed_size() {
    // Adjust values
    return array('width' => 100, 'height' => 100);
}
like image 53
mcorkum Avatar answered Dec 24 '22 15:12

mcorkum