Created
May 25, 2022 13:58
-
-
Save runezero/010507a5cabeddfbfabfee7c710df24f to your computer and use it in GitHub Desktop.
[Youtube NoCookie url] Change the youtube embeds to a nocookie url #wordpress
This file contains hidden or 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
| /** | |
| * 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