Skip to content

Instantly share code, notes, and snippets.

@rosswintle
Created November 20, 2020 17:54
Show Gist options
  • Save rosswintle/92cf7fa6fe8d00d763ba6b83369feb74 to your computer and use it in GitHub Desktop.
Save rosswintle/92cf7fa6fe8d00d763ba6b83369feb74 to your computer and use it in GitHub Desktop.
Filter to make WordPress YouTube oembeds use the nocookie version
<?php
add_filter('oembed_result', 'youtubeEmbedNocookieFilter', 10, 3);
function youtubeEmbedNocookieFilter(string $data, string $url, array $args)
{
return str_replace('src="https://www.youtube.com/embed', 'src="https://www.youtube-nocookie.com/embed', $data);
}
@szepeviktor
Copy link

The Space Force Edition 🛰️

add_filter(
    'oembed_result',
    function (string $data, string $url, array $args): string {
        return str_replace('src="https://www.youtube.com/embed', 'src="https://www.youtube-nocookie.com/embed', $data);
    },
    10,
    3
);

@rosswintle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment