Skip to content

Instantly share code, notes, and snippets.

@amitabhaghosh197
Last active August 29, 2015 14:03
Show Gist options
  • Save amitabhaghosh197/73b5e031271ff20c9acf to your computer and use it in GitHub Desktop.
Save amitabhaghosh197/73b5e031271ff20c9acf to your computer and use it in GitHub Desktop.
Convert the Youtube url to iframe src inside Reduxframework
<div class="featured-videos-section-content ">
<div class="span4 featured-videos-items">
<span id="myCode"><?php echo change_youtube() ?></span>
</div><!--------/.featured-videos-items 1---------------------->
<div class="span4 featured-videos-items">
<span id="myCode2"><?php echo change_youtube() ?></span>
</div><!--------/.featured-videos-items 2---------------------->
<div class="span4 featured-videos-items">
<span id="myCode3"><?php echo change_youtube() ?></span>
</div><!--------/.featured-videos-items 3---------------------->
</div> <!-------/featured-videos-section-content------------------------->
<?php
//Source Code http://stackoverflow.com/questions/21607808/convert-a-youtube-video-url-to-embed-code
//http://jsfiddle.net/isherwood/cH6e8/
//http://stackoverflow.com/questions/22544625/javascript-convert-youtube-vimeo-urls-into-embed-versions-for-use-on-a-forum
//http://jsfiddle.net/88Ms2/378/
?>
function change_youtube(){ ?>
<script>
<?php $options = get_option('redux_demo'); ?>
function getId(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match && match[2].length == 11) {
return match[2];
} else {
return 'error';
}
}
var myId = getId('<?php echo $options['opt-video1-editor']; ?>');
var myId2 = getId('<?php echo $options['opt-video2-editor']; ?>');
var myId3 = getId('<?php echo $options['opt-video3-editor']; ?>');
if(myId){
jQuery('#myCode').html('<iframe width="560" height="315" src="//www.youtube.com/embed/' + myId + '" frameborder="0" allowfullscreen></iframe>');
}
if(myId2){
jQuery('#myCode2').html('<iframe width="560" height="315" src="//www.youtube.com/embed/' + myId2 + '" frameborder="0" allowfullscreen></iframe>');
}
if(myId3){
jQuery('#myCode3').html('<iframe width="560" height="315" src="//www.youtube.com/embed/' + myId3 + '" frameborder="0" allowfullscreen></iframe>');
}
</script>
<?php }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment