Changing the default wordpress youtube embeded video dimensions

纵饮孤独 提交于 2019-12-10 09:33:17

问题


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>

回答1:


Try this:

add_filter( 'embed_defaults', 'change_embed_size' );

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


来源:https://stackoverflow.com/questions/17033662/changing-the-default-wordpress-youtube-embeded-video-dimensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!