-
-
Save hslaszlo/095e2f7b3548843a1f4217d272c5e5d7 to your computer and use it in GitHub Desktop.
WordPress filter for adding responsive wrapper to embedded content
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 | |
/** | |
* Filter for adding wrappers around embedded objects | |
*/ | |
function responsive_embeds( $content ) { | |
$content = preg_replace( "/<object/Si", '<div class="embed-container"><object', $content ); | |
$content = preg_replace( "/<\/object>/Si", '</object></div>', $content ); | |
/** | |
* Added iframe filtering, iframes are bad. | |
*/ | |
$content = preg_replace( "/<iframe.+?src=\"(.+?)\"/Si", '<div class="embed-container"><iframe src="\1" frameborder="0" allowfullscreen>', $content ); | |
$content = preg_replace( "/<\/iframe>/Si", '</iframe></div>', $content ); | |
return $content; | |
} | |
add_filter( 'the_content', 'responsive_embeds' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment