How can I make oEmbed work on the excerpt field so I only have to paste the youtube url in there and then be able to echo 'get_the_excerpt()'?

I also want to filter oEmbed and change the wmode but I think I found a solution for that here: http://code.hyperspatial.com/all-code/wordpress-code/oembed-wmode/

EDIT: Crap! I was wrong, it doesn't work at all, nothing happens. Anyone got a better solution?

  • I assume the answer from Rarst below now works for you? Then you could maybe edit this question to remove the addition that it does not work? It's a bit confusing now :-)
    – Jan Fabry
    Apr 6, 2011 at 7:29

1 Answer 1


Not entirely sure it is supposed to be used like this, but by analogue with the_content try this:

add_filter('the_excerpt', array($wp_embed, 'autoembed'), 9);
  • Sorry Rarst, it doesn't seem to work! I had forgotten to remove some code so it looked like it was working but it didn't.
    – Richard B
    Feb 1, 2011 at 9:23
  • @Richard B it works on my test stack for couple URLs I tried. Do you get any errors? Try with define('WP_DEBUG', true); in wp-config.pnp. Also if you are running code inside function don't forget to declare global $wp_embed;
    – Rarst
    Feb 1, 2011 at 9:28
  • I'm getting a lot of errors but none that are specific for this matter. Echoing get_the_excerpt only prints the youtube url in pure text...
    – Richard B
    Feb 1, 2011 at 13:29
  • @Richard B ah, if you use get_the_excerpt() directly this filter is never applied. Use the_excerpt() or move change the_excerpt to get_the_excerpt in add_filter(). PS and you should probably work on those "lot of errors" if possible. :) Never good thing...
    – Rarst
    Feb 1, 2011 at 13:39
  • Ah ok, I got it to work now using only the_excerpt on my test site, of course. Maybe I can change to that everywhere but it would be nice to be able to use get_the_excerpt as well. Think thats possible?
    – Richard B
    Feb 1, 2011 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.