Black Friday Coupon: BLACKFRI24
Get 50% Off Your Order. Valid until December 2nd

Fix WordPress Video Embed Stats

Photo of author

Rob Woodgate

Published:

Updated:

WordPress makes it simple to embed videos from a wide variety of sites, but while helping a client with their landing page, I noticed something odd – the videos were not collecting viewer stats.

Looking into this further, I discovered that WordPress automatically adds a “do not track” parameter to the video URL when it requests the embed code.

Fixing this was a simple matter of adding the following filter to their theme functions.php file.

// Remove DNT from video embed URLs
add_filter('oembed_fetch_url', function( $provider ) {
	$provider = remove_query_arg( 'dnt', $provider );
	return $provider;
});

If you want to remove stats for just certain providers, you can check the $provider param like so:

// Remove DNT from video embed URLs
add_filter('oembed_fetch_url', function( $provider ) {
	if ( strpos( $provider, 'vimeo.com' ) !== false ) {
		$provider = remove_query_arg( 'dnt', $provider );
	}
	return $provider;
});

Note that WordPress caches video embed codes, so the fix may not be visible for up to 24 hours.

If you want to speed this up, and you are competent editing your WP database, you can delete the _oembed_% keys from the wp_postmeta table like so:

DELETE FROM `wp_postmeta` WHERE `meta_key` LIKE '_oembed_%'

Leave a Comment