更改默认的wordpress youtube嵌入视频尺寸

时间:2013-06-10 22:11:03

标签: wordpress youtube embed vimeo dimensions

我刚刚升级到Wordpress 3.5,一个很酷的功能似乎是,如果您直接从浏览器复制Youtube网址并粘贴到单个帖子中,视频会自动嵌入!

但是,我无法弄清楚为什么以下(粘贴在标准帖子中)无法调整嵌入的尺寸:     [embed width =“20”height =“106”] https://www.youtube.com/watch?v=IjoxX5dXM8g [/ embed]

我搜索了Stackoverflow,似乎有人说你可以调整设置中的尺寸>媒体,但该功能已被弃用。另一位在http://shailan.com/2154/change-wordpress-default-embed-size-using-filters/写博客的人建议添加过滤器

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'); 

...但是在将它添加到functions.php并将宽度和高度都更改为100之后,我没有看到后期预览的差异。

现在我还在试图弄清楚如何重置粘贴到Wordpress帖子中的youtube网址的默认尺寸,而不需要在整个iframe中粘贴,即

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

1 个答案:

答案 0 :(得分:12)

试试这个:

add_filter( 'embed_defaults', 'change_embed_size' );

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