更改默认的Wordpress YouTube嵌入式视频尺寸 [英] Changing the default wordpress youtube embeded video dimensions

查看:353
本文介绍了更改默认的Wordpress YouTube嵌入式视频尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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!

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

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]

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

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

...但是将其添加到functions.php并将宽度和高度都更改为100后,我没有看到帖子预览中的差异。

... 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.

现在,我仍在尝试找出如何重置粘贴到Wordpress帖子中的youtube URL的默认尺寸,而不需要在整个iframe中进行粘贴,即

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>


推荐答案

尝试一下:

add_filter( 'embed_defaults', 'change_embed_size' );

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

这篇关于更改默认的Wordpress YouTube嵌入式视频尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆