Created
July 10, 2015 14:16
-
-
Save josephhinson/a0450288817e9559eb66 to your computer and use it in GitHub Desktop.
Make WordPress video embedding responsive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add these lines to your functions file | |
add_filter( 'embed_oembed_html', 'embed_responsively_oembed_filter', 10, 4 ) ; | |
// the following function will wrap the embedded code in a responsive frame, where the video is 100% width | |
function embed_responsively_oembed_filter($html, $url, $attr, $post_ID) { | |
$return = "<style> | |
.embed-container { | |
position: relative; | |
padding-bottom: 56.25%; | |
height: 0; overflow: hidden; max-width: 100%; | |
} | |
.embed-container iframe, | |
.embed-container object, | |
.embed-container embed { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
} | |
</style> | |
<div class='embed-container'>" | |
.$html. | |
"</div>"; | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment