PHP Responsive Videos Function for Web Embeds

Learn how to make your web videos responsive using the "responsive_videos" function in PHP. This function removes width and height attributes from video embed codes and wraps them in a responsive container.

function responsive_videos($html){
    $html = preg_replace('/(width|height)="\d*"\s/', "", $html);
    return '<div class="embed-responsive embed-responsive-16by9">' . $html . '</div>';
}

add_filter('embed_oembed_html', 'evolution_wrap_oembed', 10, 1);

.embed-responsive.embed-responsive-16by9 {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 25px;
    height: 0;
}

.embed-responsive.embed-responsive-16by9 iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

video {
    width: 100% !important;
    height: auto !important;
}