wordpress端口更改_如何在WordPress中动态更改嵌入的宽度和高度

wordpress端口更改

In our earlier article, we showed you how to set oEmbed max width in WordPress 3.5 using $content_width. That is a perfectly good solution for changing the oEmbed max width and height, but that change is global. In a recent project, we wanted to have different oEmbed sizes for the homepage and the single post page. In this article, we will show you how to dynamically change the oEmbed max width and height in WordPress using the conditional statements.

在我们之前的文章中,我们向您展示了如何使用$ content_width在WordPress 3.5中设置oEmbed最大宽度 。 对于更改oEmbed的最大宽度和高度,这是一个非常好的解决方案,但是这种更改是全局的。 在最近的项目中,我们希望主页和单个帖子页面具有不同的嵌入大小。 在本文中,我们将向您展示如何使用条件语句在WordPress中动态更改oEmbed的最大宽度和高度。

All you have to do is add the following function in your theme’s functions.php file or in a site-specific plugin.

您所要做的就是在主题的functions.php文件或特定站点的插件中添加以下功能。


//Custom oEmbed Size
function wpb_oembed_defaults($embed_size) {
if(is_front_page()) {
        $embed_size['width'] = 940;
        $embed_size['height'] = 600;
}
else {
	$embed_size['width'] = 600;
        $embed_size['height'] = 338;
}
    return $embed_size;
}
add_filter('embed_defaults', 'wpb_oembed_defaults');

You can use any of the available WordPress conditional tags. You can even have the oEmbed width be custom for each page if need be using custom fields. Hopefully you will find this article useful in your next project.

您可以使用任何可用的WordPress条件标签 。 如果需要使用自定义字段,甚至可以为每个页面自定义oEmbed宽度。 希望您会在下一个项目中发现这篇文章有用。

翻译自: https://www.wpbeginner.com/wp-themes/how-to-dynamically-change-the-oembed-width-and-height-in-wordpress/

wordpress端口更改

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值