• In my country YouTube does not work without SSL(https://). So, we use secure embed while using YouTube Sharing code. But I was forcing our writer to use oEmbed, instead of iframe code, as then we will have better dynamic control to resize. Today I was making writing the article below

    http://thetechjournal.com/all-home-entertainment/watch-this-new-mind-blowing-ipad-magic-video.xhtml

    Used the https link (https://www.youtube.com/watch?v=i-GZqni4IfA) as you could see from the source it returns without SSL.

    <iframe width="720" height="405" src="http://www.youtube.com/embed/i-GZqni4IfA?feature=oembed" frameborder="0" allowfullscreen></iframe>

    I know about the Ticket #18719 and understand @nacin’s point as its YouTube’s ignorance that handles SSL request poorly, as described many times by Otto.

    But here I want a choice. In my post I used https link, I want to force WordPress oEmbed function to return with https too.

    <iframe width="720" height="405" src="https://www.youtube.com/embed/i-GZqni4IfA?feature=oembed" frameborder="0" allowfullscreen></iframe>

    As I could understand its will not be implemented into core just yet, then I want some hooks, a switch, so I could force via function.php maybe. Its important to me and probably for other hundreds of millions of people out there.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter M Asif Rahman

    (@asif2bd)

    Just find out a new updated ticket #23149

    So, its known issue, now we need solution.

    Moderator bcworkz

    (@bcworkz)

    Our hands are tied. You can apply the 18719 patch, and the https://www.youtube urls will be handled correctly by WP. However, youtube will still send insecure content. There is nothing WordPress can do to get youtube to respond correctly. Perhaps more pressure on youtube from countries requiring secure content?

    Thread Starter M Asif Rahman

    (@asif2bd)

    Or, if thats so, I could try to make a plugin which will give user more control, like custom embed size, SSL choice in detail.

    you could hack a forced https return in the functions.php file to search for iframes that have a src starting with http://www.youtu or http://youtu and replace with https://www.yout and https://yout respectively. [I left off the ‘be’ of these urls since some of the share urls are youtu.be and youtube.com]

    //Embed Video Fix
    	function add_secure_video_options($html) {
    	   if (strpos($html, "<iframe" ) !== false) {
    	    	$search = array('src="http://www.youtu','src="http://youtu');
    			$replace = array('src="https://www.youtu','src="https://youtu');
    			$html = str_replace($search, $replace, $html);
    
    	   		return $html;
    	   } else {
    	        return $html;
    	   }
    	}
    	add_filter('the_content', 'add_secure_video_options', 10);
    Thread Starter M Asif Rahman

    (@asif2bd)

    Thanks “troutacular”, you probably faced same issue like us. Thanks for the fix.

    Thank you troutacular! I was looking for a way to add YouTube’s privacy mode to the built-in YouTube embed (and embed shortcode), so I modified your filter like this:

    //BEGIN Embed Video Fix - HTTPS and privacy mode
    	function add_secure_video_options($html) {
    	   if (strpos($html, "<iframe" ) !== false) {
    	    	$search = array('src="http://www.youtube.com','src="http://youtube.com');
    			$replace = array('src="https://www.youtube-nocookie.com','src="https://youtube-nocookie.com');
    			$html = str_replace($search, $replace, $html);
    
    	   		return $html;
    	   } else {
    	        return $html;
    	   }
    	}
    	add_filter('the_content', 'add_secure_video_options', 10);
    //END Embed Video Fix - HTTPS and privacy mode

    Embedding using youtu.be URLs didn’t work for me, so I changed that bit to youtube.com.

    UPDATE: Unfortuntely, both troutacular’s original code and my code caused a new problem — that the YouTube videos no longer resize automatically in my responsive theme. So I had to abandon this code.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Forcing SSL Return For YouTube oEmbed’ is closed to new replies.