Skip to content

Instantly share code, notes, and snippets.

@unapersona
Created March 12, 2021 11:53
Show Gist options
  • Save unapersona/215b2f02548f1c4285d4847ceee782e4 to your computer and use it in GitHub Desktop.
Save unapersona/215b2f02548f1c4285d4847ceee782e4 to your computer and use it in GitHub Desktop.
YT oEmbed to nocookie
<?php
/*
Plugin Name: YT oEmbed to nocookie
Plugin URI: http://wordpress.org/plugins/yt-nocookie/
Description: Modify the YouTube oEmbed to use the youtube-nocookie.com server
Author: Jorge González
Version: 1.0.0
Author URI: http://unapersona.com
*/
namespace WUP\oEmbed;
class YT {
function init() {
add_filter( 'oembed_result', [ $this, 'oembed_result' ], 10, 3 );
}
function oembed_result( $html, $url, $args ) {
if ( false === strpos( $html, 'youtube.com/embed/' ) ) {
return $html;
}
return strtr(
$html,
[ 'youtube.com/embed/' => 'youtube-nocookie.com/embed/' ]
);
}
}
add_action( 'plugins_loaded', [( new YT() ), 'init'] );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment