Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

2 CommentsLeave a Reply

  1. Jonathan

    Is this code not enough?

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

  2. Fernando

    Thanks for the tip but has a problem, that the media content doesn’t adapt to the sidebar width, something that we can control with the embed code and not with the plugin or the code.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.