Skip to content

Instantly share code, notes, and snippets.

@runezero
Created May 25, 2022 13:58
Show Gist options
  • Select an option

  • Save runezero/010507a5cabeddfbfabfee7c710df24f to your computer and use it in GitHub Desktop.

Select an option

Save runezero/010507a5cabeddfbfabfee7c710df24f to your computer and use it in GitHub Desktop.
[Youtube NoCookie url] Change the youtube embeds to a nocookie url #wordpress
/**
* Modify YouTube oEmbeds to use youtube-nocookie.com
*
* @param $cached_html
* @param $url
*
* @return string
*/
function wpdev_filter_youtube_embed( $cached_html, $url = null ) {
// Search for youtu to return true for both youtube.com and youtu.be URLs
if ( strpos( $url, 'youtu' ) ) {
$cached_html = preg_replace( '/youtube\.com\/(v|embed)\//s', 'youtube-nocookie.com/$1/', $cached_html );
}
return $cached_html;
}
add_filter( 'embed_oembed_html', 'wpdev_filter_youtube_embed', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment