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:


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

<div class="textwidget">Before


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


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 [embed] shortcode, use the following in the Text Widget:

[video src="http://youtu.be/JQ_2De2cnzI&rel=0&showinfo=0&w=120"]

For more info on the [video] shortcode, see the Codex.

  • That didn't do it: the embed is still not appearing. Anything else that might be getting in the way? – feetwet Oct 26 '14 at 23:36
  • Updated my answer. I'm not sure why the [embed] shortcode doesn't work in the Text Widget, but [video] works OK. – Gabriel Oct 27 '14 at 0:16

The suggested code from @Gabriel do not work for me but this one do.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.