Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Enable oEmbed in WordPress Text Widgets

Last updated on by
Follow WPBeginner on YouTube
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.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • Jonathan

    Is this code not enough?

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

  • 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.