I have impelmented a custom code to wrap a video embed in a .embed-responsive class to make it responsive with CSS then:


function kadabra_responsive_embed( $html ) {
    return '<div class="embed-responsive embed-responsive-16by9">' . $html . '</div>';
add_filter( 'embed_oembed_html', 'kadabra_responsive_embed', 10, 3 );
add_filter( 'video_embed_html', 'kadabra_responsive_embed' );


.embed-responsive-16by9 {
  height: 0;
  padding-bottom: 56.25%;

which works pefect for a video embed. However, it also wraps other embeds, like a Twitter embed, which it is not required for. Any way to make it exclusive for video embeds only?

  • Just realized you mentioned shortcodes, but it sounds like you mean video oEmbeds in general, where you can also paste the url into the content editor. So I didn't have shortcodes specifically in mind in my answer
    – birgire
    Commented Jul 25, 2017 at 11:13
  • @birgire, thanks! I did actually mean video embeds via the Media button, so I think it is oEmbeds (sorry, I am not yet well versed in WP terms). I think the solution below should work!
    – Deka87
    Commented Jul 25, 2017 at 11:20

1 Answer 1


You could create a new callback for the embed_oembed_html filter and target the third input argument, the oembed $url.

Then you could e.g. create boolean helper functions like (untested):

function is_oembed_from_video_specific_hosts_wpse274552( $url )
    return in_array(
        parse_url( $url, PHP_URL_HOST ),
             'vimeo.com',  // ... etc

or a more detailed (more expensive) checks like (untested):

function is_video_oembed_wpse274552( $url )
    $video_providers = [
        '#https?://www\.facebook\.com/video\.php.*#i', // ... etc

    $is_video_oembed = false;
    foreach( $video_providers as $video_provider )
        if ( preg_match( $video_provider , $url ) ) {
             $is_video_oembed = true;
    return $is_video_oembed;

Note that oEmbed providers can be modified, added and deleted in the WordPress core and through filters. That could affect the above checks.

Hope you can adjust it to your needs!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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