Display oEmbed in the_excerpt

I am currently adding

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

to my functions.php file to no avail any other suggestions would be great. Also if I add $content-width to functions.php the settings are ignored. I have wp-debug on with no errors/warnings and no errors are being logged.

Solutions Collecting From Web of "Display oEmbed in the_excerpt"

Without knowing more about your theme I can only hazard a few guesses. What are you inputting as an excerpt, what is the current output you are seeing for your excerpt, and what is the expected output? Are you seeing the URL show up in the excerpt, or is it being stripped?

Oembed

  1. Are you being sure to scope in $wp_embed?

    global $wp_embed;
    add_filter( 'the_excerpt', array( $wp_embed, 'autoembed' ), 9 );
    
  2. Are you using shortcodes?

    Due to some conflicts and ordering necessary to process [embed] shortcodes there are some hacks to get around making things work correctly. You may need to emulate the same to get it working on excerpts.

    // untested code: it may not be this simple, I haven't done it before
    global $wp_embed
    add_filter( 'the_excerpt', array( $wp_embed, 'run_shortcode' ), 9 );
    add_shortcode( 'embed', '__return_false', 9 );
    add_filter( 'the_excerpt', array( $wp_embed, 'autoembed' ), 9 );
    
  3. Is your template using the_excerpt() or is it relying on the automatic excerpting done by the_content(), or is it using get_the_excerpt()?

    Those are all different functions doing different things at different stages and may require modified handling.

    global $wp_embed;
    add_filter( 'get_the_excerpt', array( $wp_embed, 'autoembed' ), 9 );
    

Content-Width

Without knowing more, I can only suggest that you may be typing it wrong, or that your embeds aren’t larger than the setting you’re using, so they aren’t getting scaled down.

// use an underscore(_), not a hyphen(-)
// like this
$content_width = 600;
// not this
$content-width = 600;