Last active
October 19, 2016 21:52
-
-
Save vovafeldman/c5d55452147878e94a96c47825a9d791 to your computer and use it in GitHub Desktop.
Freemius - YouTube and Vimeo Shortocdes
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
$video-max-width: 640px; | |
$video-max-height: 360px; | |
.responsive-container { | |
max-width: $video-max-width; | |
max-height: $video-max-height; | |
overflow: hidden; | |
.responsive-container | |
{ | |
position: relative; | |
padding-bottom: 53.25%; | |
padding-top: 18px; | |
height: 0; | |
margin: 0; | |
&, iframe | |
{ | |
max-width: $video-max-width; | |
max-height: $video-max-height; | |
} | |
iframe | |
{ | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
} | |
} | |
} |
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 | |
/** | |
* Render YouTube/Vimeo video shortcode. | |
* | |
* @author Vova Feldman | |
* | |
* @param array $atts | |
* @param null $quote | |
* @param string $shortcode | |
* | |
* @return string | |
*/ | |
function freemius_video_shortcode( $atts, $quote = null, $shortcode = 'youtube' ) { | |
$video_id = $atts[0]; | |
if ( 'youtube' === $shortcode ) { | |
$base_url = "https://www.youtube.com/embed/{$video_id}"; | |
$args = array( | |
'rel' => '0', | |
'VQ' => 'HD720', | |
'light' => 'light', | |
'showinfo' => '0', | |
); | |
} else if ( 'vimeo' === $shortcode ) { | |
$base_url = "https://player.vimeo.com/video/{$video_id}"; | |
$args = array( | |
'badge' => '0', | |
); | |
} | |
return sprintf( | |
'<div class="responsive-container"><div class="responsive-container-inner"><iframe width="640" height="360" src="%s" frameborder="0" allowfullscreen=""></iframe></div></div>', | |
"{$base_url}?" . http_build_query( $args ) | |
); | |
} | |
/** | |
* Add markdown special shortcodes. | |
* | |
* @author Vova Feldman | |
*/ | |
function freemius_add_video_shortcodes() { | |
add_shortcode( 'youtube', 'freemius_video_shortcode' ); | |
add_shortcode( 'vimeo', 'freemius_video_shortcode' ); | |
} | |
add_action( 'init', 'freemius_add_video_shortcodes' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment