Skip to content

Instantly share code, notes, and snippets.

@350d
Created October 30, 2014 16:40
Show Gist options
  • Save 350d/effc1f1e5eef7c092cac to your computer and use it in GitHub Desktop.
Save 350d/effc1f1e5eef7c092cac to your computer and use it in GitHub Desktop.
Wordpress: Youtube + Vimeo shortcodes for responsive layout
function appthemes_add_quicktags() {
if (wp_script_is('quicktags')){
?>
<script type="text/javascript">
QTags.addButton( 'yt_embed', 'Youtube', '[youtube id="', '"]', 'y', 'Youtube Video', 1 );
QTags.addButton( 'vm_embed', 'Vimeo', '[vimeo id="', '"]', 'v', 'Vimeo Video', 2 );
</script>
<?php
}
}
add_action( 'admin_print_footer_scripts', 'appthemes_add_quicktags' );
function youtube_shortcode($atts) {
extract(shortcode_atts(array('id' => 'KO8EPkgug4c'), $atts));
return '<div class="ytplayer"><iframe src="https://youtube.com/embed/'.$atts['id'].'?controls=1&amp;autohide=1&amp;vq=hd720&amp;iv_load_policy=3&amp;rel=0&amp;showinfo=0" allowfullscreen=""></iframe></div>';
}
function vimeo_shortcode($atts) {
extract(shortcode_atts(array('id' => '12345678'), $atts));
return '<div class="vmplayer"><iframe src="//player.vimeo.com/video/'.$atts['id'].'?title=0&byline=0&portrait=0&hd=0&autoplay=0" allowfullscreen=""></iframe></div>';
}
add_shortcode('youtube', 'youtube_shortcode');
add_shortcode('vimeo', 'vimeo_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment