amitabhaghosh197
6/25/2014 - 2:02 PM

Convert the Youtube url to iframe src inside Reduxframework

Convert the Youtube url to iframe src inside Reduxframework

 <?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 } 
<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------------------------->