Skip to content

Instantly share code, notes, and snippets.

@besimhu
Created March 15, 2015 16:02
Show Gist options
  • Save besimhu/8a55a27b87b8171f9c2b to your computer and use it in GitHub Desktop.
Save besimhu/8a55a27b87b8171f9c2b to your computer and use it in GitHub Desktop.
To make videos responsive, mostly anything with <iframe> use the below function, and don’t forget to add the css as well.
// Add responsive container to embed videos
function forty_responsive_video( $html ) {
//add http protocol
$html = str_replace('<iframe src="//', '<iframe src="http://', $html);
return '<div class="flex-video">' . $html . '</div>';
}
add_filter( 'embed_oembed_html', 'forty_responsive_video', 10, 3 );
add_filter( 'video_embed_html', 'forty_responsive_video' );
// Make videos responsive
.flex-video {
padding-top: 0;
padding-bottom: 56.3%;
position: relative;
iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment