How do I embed in a text widget?

I’m trying to embed a YouTube video in a Text Widget and WordPress 4.0 is stripping out the embed when rendering. For example, if I put this in the body of the widget:

Before
http://youtu.be/JQ_2De2cnzI&rel=0&showinfo=0&w=120
After

then when I inspect the div in the browser I end up with this:

<div class="textwidget">Before

After</div>

How can I get WordPress to keep the embed in the widget?

2 Answers
2

Shortcodes are not supported in the Text Widget by default. Add the following to your functions.php:

// Enable shortcodes in WP Text Widget
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode', 11);

Instead of wrapping the video URL in the shortcode, use the following in the Text Widget:


For more info on the shortcode, see the Codex.

Leave a Comment