Skip to content

Instantly share code, notes, and snippets.

@alexstandiford
Created December 23, 2016 15:50
Show Gist options
  • Save alexstandiford/6a6bc9de749302913390539836b5ebe3 to your computer and use it in GitHub Desktop.
Save alexstandiford/6a6bc9de749302913390539836b5ebe3 to your computer and use it in GitHub Desktop.
Alters oembed querystring parameters
<?php
/**
* Cleans up YouTube Video Embeds
**/
function imp_custom_youtube_querystring( $html, $url, $args ) {
if(strpos($html, 'youtube')!= FALSE) {
$args = [
'rel' => 0,
'controls' => 0,
'showinfo' => 0,
'modestbranding' => 1,
];
$params = '?feature=oembed&';
foreach($args as $arg => $value){
$params .= $arg;
$params .= '=';
$params .= $value;
$params .= '&';
}
$result = str_replace( '?feature=oembed', $params, $html );
}
return $result;
}
add_filter('oembed_result', 'imp_custom_youtube_querystring', 10, 3);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment