3

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.

3

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


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

[embed src="https://www.youtube.com/watch?v=jfNOdsvMke4" desc="some description"]

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.

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.