Responsive WordPress oEmbed Videos

Get WordPress oEmbed videos to be responsive.

functions.php
add_filter('embed_oembed_html', 'wrap_oembeds', 99, 4);
function wrap_oembeds($content, $url, $attr, $post_id) {
    return '<div class="oembed-container">' . $content . '</div>';
}
style.css
.oembed-container {
    position: relative;
    overflow: hidden;
    height: 0;
    padding-top: 30px;
    padding-bottom: 56.25%;
}

.oembed-container iframe,
.oembed-container object,
.oembed-container embed{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
Posted In: Snippets     ||      Tags: Wordpress