Last active
September 29, 2015 12:17
-
-
Save byjml/1599592 to your computer and use it in GitHub Desktop.
Respensive embed and iframe for WordPress
This file contains hidden or 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 | |
/* Hook responsive_embed_wrapper function to 'the_content' filter. */ | |
add_filter( 'the_content', 'responsive_embed_wrapper', 20 ); | |
/** | |
* Adds wrapper and container divs to make <object> and <iframe> embeds responsive to | |
* CSS media queries. | |
* | |
* | |
* @link http://webdesignerwall.com/tutorials/css-elastic-videos | |
* | |
* @param String $content The Content. | |
* @return String $content Modified content. | |
*/ | |
function responsive_embed_wrapper( $content ) { | |
/* Guess work: searches <object></object> and <iframe></iframe> | |
* and wrapps them with two divs. | |
*/ | |
$content = preg_replace( | |
array( | |
"/<p>(.*?)<object/", | |
"/<p>(.*?)<iframe/", | |
"/<\/object>(.*?)<\/p>/", | |
"/<\/iframe>(.*?)<\/p>/" | |
), | |
array( | |
"<div class='media-wrapper'><div class='media-container'>$1<object", | |
"<div class='media-wrapper'><div class='media-container'>$1<iframe", | |
"</object>$1</div></div>", | |
"</iframe>$1</div></div>" | |
), | |
$content | |
); | |
return $content; | |
} |
This file contains hidden or 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
/* | |
* As per: http://webdesignerwall.com/tutorials/css-elastic-videos | |
* | |
* Modified for personal flavour. | |
*/ | |
/* Videos and embed settings */ | |
video { | |
height: auto; | |
width: 100%; | |
max-width: 100%; | |
} | |
.media-wrapper, | |
.media-container { | |
max-width: 100%; /* Restricts the width of the embedded media (iframe/embed) to the maximum area of the parent element. */ | |
} | |
.media-container { | |
height: 0; | |
position: relative; | |
padding-bottom: 56.25%; | |
padding-top: 24px; | |
overflow: hidden; | |
} | |
.media-container iframe, | |
.media-container object, | |
.media-container embed { | |
height: 100%; | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment