1

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.

1 Answer 1

4

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;
2
  • I found that I was setting it correctly (ignoring the typo in my comment) although it only appears to work on the video oEmbeds not the tweet one which just happened to be the type I was testing on. I am using theme unit test data, have tried both with global and withough :/ excerpt printed as follows: Really cool to read through and find so much awesomeness added to WordPress 3.6 while I was gone. I should take three weeks off more often. — Andrew Nacin (@nacin) April 3, 2013 This post tests WordPress’ Twitter Embeds feature. Sep 9, 2014 at 9:31
  • The $content_width feature is a "theme feature" so it will be a matter of implementation as to whether or not it's used correctly for each embed, if it's not working for something that WP supports you can file a bug, if it's via a plugin you'll need to contact the author.
    – totels
    Sep 9, 2014 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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