Vimeo Embeds With "Do Not Track"
Adds Vimeo's dnt=1 setting to every embedded Vimeo video, which stops Vimeo from setting tracking cookies or collecting session data for your visitors.
Opens WPIDE on
Code
add_filter( 'oembed_fetch_url', function ( $provider ) {
return false !== strpos( $provider, 'vimeo.com' ) ? add_query_arg( 'dnt', '1', $provider ) : $provider;
} );
add_filter( 'embed_oembed_html', function ( $html, $url ) {
if ( false === stripos( $url, 'vimeo.com' ) || ! class_exists( 'WP_HTML_Tag_Processor' ) ) {
return $html;
}
$tags = new WP_HTML_Tag_Processor( $html );
while ( $tags->next_tag( 'iframe' ) ) {
$src = (string) $tags->get_attribute( 'src' );
if ( false !== strpos( $src, 'player.vimeo.com' ) ) {
$tags->set_attribute( 'src', add_query_arg( 'dnt', '1', $src ) );
}
}
return $tags->get_updated_html();
}, 10, 2 );
Notes
Vimeo still sees the visitor's IP address when the player loads; combine with a click-to-load snippet if you need to avoid that too.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.