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

All what you have to do is add the following code in your theme’s functions.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 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.

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.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!

Pin It on Pinterest

Add address