Switch every YouTube embed to youtube-nocookie.com, which doesn't set tracking cookies until the visitor plays the video.
add_filter( 'embed_oembed_html', function ( string $html, string $url ): string {
if ( ! str_contains( $html, 'youtube.com/embed/' ) ) {
return $html;
}
return str_replace( 'youtube.com/embed/', 'youtube-nocookie.com/embed/', $html );
}, 10, 2 );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Standard YouTube embeds set cookies as soon as the page loads, even if nobody presses play. YouTube’s privacy-enhanced mode, on youtube-nocookie.com, waits until the video is played. This snippet switches every embed automatically.
When WordPress turns a YouTube link into an embed, the HTML passes through embed_oembed_html. The snippet swaps the iframe’s address to the youtube-nocookie.com version. The video, player and controls are the same.
View a post with a YouTube embed and inspect the iframe. Its src should start with https://www.youtube-nocookie.com/embed/.