Skip to content

Instantly share code, notes, and snippets.

@paulstelzer
Last active March 25, 2018 10:22
Show Gist options
  • Save paulstelzer/69effa882a50473e15c57edaa1468e73 to your computer and use it in GitHub Desktop.
Save paulstelzer/69effa882a50473e15c57edaa1468e73 to your computer and use it in GitHub Desktop.
WordPress Change oEmbed of youtube.com Links automatically to youtube-nocookie.com to fulfill the new EU-GDPR
// Add this to your plugin or functions.php file of your theme
// Source: https://gdgts.de/wordpress-youtube-embed/
function youtube_add_nocookie( $cached_html, $url, $attr, $post_id ) {
if ( preg_match('#https?://(www\.)?youtu#i', $url) ) {
return preg_replace(
'#src=(["\'])(https?:)?//(www\.)?youtube\.com#i',
'src=$1$2//$3youtube-nocookie.com',
$cached_html
);
}
return $cached_html;
}
add_filter( 'embed_oembed_html', 'youtube_add_nocookie', 99, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment