• Hi there,
    for the GDPR Youtube provides the “-nocookie” option.
    If you click the share button at a Youtube video, you get this code:
    <iframe width="560" height="315" src="https://www.youtube.com/embed/WoQHOx6XS-E?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
    If you check the privacy mode you get this:
    <iframe width="560" height="315" src="https://www.youtube<strong>-nocookie</strong>.com/embed/WoQHOx6XS-E?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

    I created a test page with the following code:

    1
    
    
    
    2
    
    <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/WoQHOx6XS-E?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
    
    3
    
    [video src="https://www.youtube.com/watch?v=WoQHOx6XS-E"]
    
    4
    
    [video src="https://www.youtube-nocookie.com/watch?v=WoQHOx6XS-E"]
    
    5
    
    [video src="https://www.youtube-nocookie.com/embed/WoQHOx6XS-E?rel=0"]

    Number 1, 2 and 3 are working, 4 and 5 are not. I really would like to use 4 or 5 because that’s the way we’ve set up our side and we use the ‘poster=’ tag to provide our own thumbnails.
    Any idea if this “youtube-nocookie.com” url can be supported? I guess this must be adjusted in the wordpress core functionality, so that the video shortcode is updated?
    Thanks

    EDIT: Number 1 is just the url: “https://www. youtube.com/watch?v=WoQHOx6XS-E”

    • This topic was modified 6 years, 9 months ago by rlonau.
Viewing 8 replies - 1 through 8 (of 8 total)
  • @rlonau – As far as I can see 4 is not working because “youtube-nocookie” is not able to resolve that URL (resolves to a 404 not found page) while 5 appears to be fine if I copy and paste your example (https://take.ms/qwAjg … although perhaps not what you are wanting?!).

    It also appears the core oEmbed code would need to be adjusted and/or a plugin supporting “youtube-nocookie” as an oEmbed URL would need to be added to support the URL on its own line approach as well.

    ~ Cais.

    Thread Starter rlonau

    (@rlonau)

    Hi @cais,
    thanks for your feedback. What do you mean “5 appears to be fine”? You mean the link itself works. But the video is not shown in the wordpress page/post, right?

    Here’s a screenshot of my test page with option 3, 4 and 5. While 3 is shown as video, 4 and 5 are not.
    https://ibb.co/h7nwky
    Thanks

    @rlonau – The best I can get is also just a display of the link to the “no cookie” video which in and of itself might be the best approach depending on the concerns and importance of not using cookies on the site.

    I’m not seeing anything specifically in “trac” related to YouTube no-cookie oEmbeds and the behavior we are seeing, there might be a case to add this.

    ~ Cais.

    Hi, seeking the same (youtube-nocookies.com) for Youtube embeds, and also wanting to “convert” all previously entered Youtube URLs automatically (there hare hundreds on the site in question) I had hoped to be able to use the oembed_dataparse filter hook. Sadly, the example here https://wpexplorer-themes.com/total/snippets/add-nocookie-to-wordpress-oembeded-youtube-videos/ does not seem to work at all. I tried other preg_replace routines bus still nothing.

    Then I found someone suggesting on https://wordpress.stackexchange.com/questions/155755/youtube-oembed-and-privacy-enhanced-mode to use wp_oembed_add_provider like this (untested)

    
    wp_oembed_add_provider(
        '#https://(www\.)?youtube-nocookie\.com/embed.*#i',
        'https://www.youtube-nocookie.com/oembed', true );
    

    but that would not help me with the old Youtbe URLs though… unless I do a content filter before the embed code runs. Hmmm, will have to work futher on this.

    In any case, I have the feeling WordPress should really consider supporting the cookieless embed in light of all the new GDPR stuff.

    Oh, hang on. The code on https://wpexplorer-themes.com/total/snippets/add-nocookie-to-wordpress-oembeded-youtube-videos/ does work on a clean test installation. It must be conflicting with another plugin. Jetpack maybe?

    For completeness and future reference, I’ll repeat it here:

    
    // Add "nocookie" To WordPress oEmbeded Youtube Videos
    function wpex_youtube_nocookie_oembed( $return ) {
    	$return = str_replace( 'youtube', 'youtube-nocookie', $return );
    	return $return;
    }
    add_filter( 'oembed_dataparse', 'wpex_youtube_nocookie_oembed' );
    

    With this snippet in your functions.php (or custom plugin), you can use the normal Youtube page URL to auto-embed with the youtube-nocookie.com domain. Excellent stuff ?? if I can figure out what is messing this up on my particular site…

    UPDATE: if anyone runs into the same problem of the above code “not working” then the explanation is this. The code filters the oembed response only once. After that, the response is then cached by WordPress in the database in the _postmeta table with a _oembed_UNIQUEKEY. This means if your normal embed was already cached before adding the filter, there will be no filtering at all. I guess I’ll have to figure out how to either flush all these previously stored embed snippets from the DB or filter them too…

    UPDATE 2: found a filter that does the work on already cached embed html as well.

    
    // Add "nocookie" To WordPress oEmbeded Youtube Videos
    function ev_youtube_nocookie_oembed( $html, $url ) {
    	if ( !empty( $url ) && strpos($url,'youtube.com') !== false ) {
    		$html = str_replace( 'youtube.com', 'youtube-nocookie.com', $html );
    	}
    	return $html;
    }
    add_filter( 'embed_oembed_html', 'ev_youtube_nocookie_oembed', 10, 2 );
    

    UPDATE 3: turns out I wasn’t wrong about Jetpack interfering. New code now works for both normal WordPress and Jetpack:

    
    // Add "nocookie" To WordPress oEmbeded Youtube Videos
    function ev_youtube_nocookie_oembed( $html ) {
    	return str_replace( 'youtube.com', 'youtube-nocookie.com', $html );
    }
    add_filter( 'embed_oembed_html', 'ev_youtube_nocookie_oembed' ); // WordPress
    add_filter( 'video_embed_html', 'ev_youtube_nocookie_oembed' ); // Jetpack
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘video shortcode youtube nocookie not working’ is closed to new replies.