Last active
March 25, 2018 10:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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