Embed Tweets, YouTube Videos, and More into Text Widgets with a URL

Embed Tweets, YouTube Videos, and More into Text Widgets with a URL

In a WordPress post, you can simply place the URL from a YouTube video or tweet into your editor, and the video or tweet will automatically be embedded.

You can also do this with media from a number of other sites such as Flickr and Vimeo and Slideshare. (See the entire list here.)

Trying to do that in a text widget, however, doesn’t work.

But there’s a way around that.

Code Snippet for Embeds in Text Widgets

As you’ll be changing your theme for solution, you should probably consider either creating a child theme or making your own simple plugin to use.

Place the following bit of code in your functions file. (Appearance > Editor > Theme Functions – functions.php)

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

Here’s a YouTube video and a tweet I was able to embed in regular text widgets just by inserting the URLs.

embeded-media2

Once embedding in a text widget is this easy, you just may find yourself doing it more often.

Thanks to wpsnipp for this.