Enable oEmbed for Excerpts or Custom  Fields

I’m in the process of finalizing a content curation WordPress plugin, and this little tidbit just saved me some time. WordPress has automatic video embedding functionality provided by oEmbed for the_content(), but not the the_excerpt() or get_the_meta(). In order to display a YouTube video from a Google Reader RSS feed, I needed to add this filter to the_excerpt(). This could easily be used on get_the_meta() also.

oEmbed & Excerpts

Adding the following bit of code to your functions.php will enable oEmbed filtering for the_excerpt():

add_filter('the_excerpt', array($GLOBALS['wp_embed'], 'autoembed'), 9);

oEmbed & Custom Fields

Adding the following bit of code to your functions.php will enable oEmbed filtering for get_the_meta():

add_filter('get_post_metadata', array($GLOBALS['wp_embed'], 'autoembed'), 9);

That’s it!

Meet the Author

Kevin Leary, WordPress Consultant

I'm a freelance web developer and WordPress consultant in Boston, MA with 17 years of experience building websites and applications. View a portfolio of my work or request an estimate for your next project.