Adding a video description in a similar way to a image caption

I’m looking for a solution to add a short description to a embed video that will allow for it to be styled a bit like the one that is used for images.

The only option I have found is using JavaScript to find the paragraph after the image and add a class which is then styled. This obviously could result in human error depending on the content after the image.

1 Answer
1

It will be interesting to see how the new evolving WP Gutenberg editor will handle shortcodes and embeds.


If you use the shortcode for embedding, then a semi workaround, without UI support:


where the custom desc attribute is supported with with this kind of wrapper:

add_filter( 'embed_oembed_html', function( $return, $url, $attr )
{
    if( ! isset( $attr['desc']))
        return $return;

    return sprintf( 
        '<div class="oembed-wrapper">%s<span>%s</span></div>', 
        $return, 
        esc_html( $attr['desc'] ) 
    );

}, 10, 3 );

You would then need to adjust it further with some CSS.

ps: there are ways to add UI to shortcodes, like the Shortcake plugin.

Leave a Comment