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

How to Enable oEmbed in WordPress Text Widgets

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
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 experts 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 »


  1. Jonathan says:

    Is this code not enough?

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

  2. Fernando says:

    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.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.