如何在WordPress文本小部件中启用oEmbed

Recently, one of our users asked us how to enable oEmbed in WordPress text widgets. oEmbed is a protocol that allows your blog to ask an oEmbed enabled website to provide HTML needed to embed dynamic content. In simple words, it allows you to just paste a YouTube video URL in a blog post and let WordPress embed it automatically. You can adjust the oembed maximum width manually, or dynamically change oEmbed content width and height. However, you can not embed content in a text widget using oEmbed. In this article, we will show you how to enable oEmbed in WordPress text widgets.

最近,我们的一位用户问我们如何在WordPress文本小部件中启用oEmbed。 oEmbed是一种协议,允许您的博客要求启用oEmbed的网站提供嵌入动态内容所需HTML。 简而言之,它允许您将YouTube视频URL粘贴到博客文章中,然后让WordPress自动嵌入。 您可以手动调整嵌入的最大宽度 ,也可以动态更改嵌入的内容的width和height 。 但是,您无法使用oEmbed将内容嵌入文本小部件中。 在本文中,我们将向您展示如何在WordPress文本小部件中启用oEmbed。

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

您要做的就是在主题的functions.php文件或特定站点的插件中添加以下代码:


add_filter( 'widget_text', array( $wp_embed, 'run_shortcode' ), 8 );
add_filter( 'widget_text', array( $wp_embed, 'autoembed'), 8 );

Once you have done that, then you are done. You have successfully enabled oEmbed for text widgets. You can head over to Appearance » Widgets to test it. Simply add a Youtube video URL in your text widget, and watch the magic.

完成之后,就可以完成。 您已成功为文本窗口小部件启用了oEmbed。 您可以转到Appearance»Widgets进行测试。 只需在您的文本小部件中添加Youtube视频URL,然后观看魔术。

For those of you who want to know what this code does, it simply adds a filter widget_text allowing text widgets to run shortcode for oEmbed and auto-embed content.

对于那些想知道此代码的功能的人,只需添加一个过滤器widget_text允许文本小部件为嵌入和自动嵌入的内容运行简码。

For those who don’t like to deal with code, then you can simply activate Text Widget oEmbed plugin. It literally does the same thing. The plugin only has 2 lines of code that we shared above.

对于那些不喜欢处理代码的人,您只需激活Text Widget oEmbed plugin即可 。 从字面上看,它做同样的事情。 该插件只有我们上面共享的两行代码。

We hope that this article helped you enable oEmbed in text widgets. If you have any questions or comments, then please let us know by leaving a comment below.

我们希望本文能帮助您在文本小部件中启用oEmbed。 如果您有任何疑问或意见,请在下面留言以告知我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-enable-oembed-in-wordpress-text-widgets/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值