# Privacy-Enhanced Mode for YouTube Embeds

> Switches every embedded YouTube video to youtube-nocookie.com, YouTube's privacy-enhanced mode, which does not set tracking cookies until the visitor plays the video.

- Type: PHP
- Runs: Run everywhere
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: youtube, privacy, embeds
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/youtube-privacy-enhanced-mode/

## Code

```php
add_filter( 'embed_oembed_html', function ( $html ) {
    $result = preg_replace( '#//(?:www\.)?youtube\.com/embed/#i', '//www.youtube-nocookie.com/embed/', $html );

    return null === $result ? $html : $result;
}, 20 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Privacy-Enhanced Mode for YouTube Embeds" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
