Family Encyclopedia >> Electronics

How to Enable oEmbed in WordPress Text Widgets: Quick and Reliable Fix

As experienced WordPress developers, we've fielded this question many times: how do you enable oEmbed in text widgets? oEmbed is a powerful protocol that lets WordPress pull embed code directly from supported sites like YouTube. Simply paste a video URL into a post, and it auto-embeds—no extra hassle. You can even tweak the max width or dynamically adjust dimensions. By default, though, text widgets don't support it. Here's our proven method to change that.

Add this code to 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 );

That's it—you've enabled oEmbed for text widgets. Head to Appearance » Widgets, add a Text widget to a sidebar, paste a YouTube URL, and save. Watch it transform into an embedded player instantly.

Curious about the code? It hooks two filters into widget_text content: one for shortcode processing and one for auto-embedding, unlocking full oEmbed functionality.

Prefer a no-code option? Install the Text Widget plugin—it uses exactly these two lines under the hood.

This tweak has helped countless sites embed richer content effortlessly. Questions? Drop a comment below—we're here to help.