I'm aware that WordPress has oEmbed functionality. But the content to be embedded has to be on it's own line like so:

Lorem Ipsum


More Lorem Ipsum

Unfortunately, my markup looks like this so oEmbed doesn't work and I have to use a plugin.


Is there anyway I can get oEmbed to work without this plugin? A line or two in functions.php would be better than this plugin.


Just use the [embed] shortcode around your items.

  • 1
    I so overkilled it, didn't I... :) – Rarst May 15 '13 at 20:29
  • This works great because it's already built in (I can't believe I missed it!). The only criticism is that I have to teach users to type in the embed code with a specific width. Hmmm. – BFTrick May 15 '13 at 21:25

There is bit of special filtering by WP_Embed class that turns standalone links into target for embedding:

 * Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} for potential embedding.
 * @uses WP_Embed::autoembed_callback()
 * @param string $content The content to be searched.
 * @return string Potentially modified $content.
function autoembed( $content ) {
    return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );

If we take that logic and adjust regex for your use case:

add_filter( 'the_content', 'autoembed_list_items', 8 );

function autoembed_list_items( $content ) {

    global $wp_embed;

    return preg_replace_callback( '|<li>(https?://[^\s"]+)</li>|im', array( $wp_embed, 'autoembed_callback' ), $content );
  • This works very well thanks! Is there any way I can set width of these items (but not other oEmbed items)? – BFTrick May 15 '13 at 21:23
  • +1 for the nicest "shooting with cannons at mice" answer of this year. – kaiser May 15 '13 at 21:39
  • @BFTrick might be possible, but will need to reverse-engineer much more of it and I already overkilled it in first place :) – Rarst May 15 '13 at 21:42

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.