Last active
May 10, 2018 08:32
-
-
Save daveaspinall/41942c0757a18c7ebf645c404fc01e06 to your computer and use it in GitHub Desktop.
WordPress Image Embed
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
| public function embedWrapper($html, $url, $attr) | |
| { | |
| $classes = ['post-embed']; | |
| if (strpos($url, 'youtu.be') !== false || strpos($url, 'youtube.com') !== false || strpos($url, 'vimeo') !== false) { | |
| $classes[] = 'post-embed--video'; | |
| } else if (strpos($url, 'twitter.com') !== false) { | |
| $classes[] = 'post-embed--twitter'; | |
| } | |
| $classes = implode(' ', $classes); | |
| return '<figure class="' . $classes . '">' . $html . '</figure>'; | |
| } | |
| add_filter('embed_oembed_html', 'embedWrapper', 10, 3); | |
| .post-embed { | |
| margin: 24px 0; | |
| } | |
| .post-embed--video { | |
| position: relative; | |
| padding-top: calc(100% * 9/16); | |
| } | |
| .post-embed--video iframe, | |
| .post-embed--video object { | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| } | |
| .post-embed--twitter { | |
| margin-left: auto; | |
| margin-right: auto; | |
| max-width: 500px; | |
| background-color: #fff; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment