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
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.
Once embedding in a text widget is this easy, you just may find yourself doing it more often.
Thanks to wpsnipp for this.Tags: