Family Encyclopedia >> Electronics

How to enable oEmbed in WordPress text widgets

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 the necessary HTML to embed dynamic content. In a nutshell, it allows you to simply paste a YouTube video URL into a blog post and let WordPress automatically embed it for you. You can adjust the built-in maximum width manually or dynamically change the width and height of the content. However, you cannot embed content in a text widget using oEmbed. In this article, we will show you how to enable oEmbed in WordPress text widgets.

All you have to do is add the following code in your theme funciones.php file or a site-specific plugin:

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

Once you've done that, then you're done. You have successfully enabled oEmbed for text widgets. You can head over to Appearance » Widgets to try it out. Just add a Youtube video URL in your text widget and watch the magic.

For those of you who want to know what this code does, just add a filter widget_text Allowing text widgets to execute shortcode for embedded and auto-embedded content.

For those who don't like to work with code, you can simply turn on the Text Widget plugin. It literally does the same thing. The plugin only has 2 lines of code that we shared above.

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