Skip to content

Instantly share code, notes, and snippets.

@tacensi
Created March 12, 2018 17:12
Show Gist options
  • Save tacensi/6e0aa230af3e8256c455c7a2db7b9ec9 to your computer and use it in GitHub Desktop.
Save tacensi/6e0aa230af3e8256c455c7a2db7b9ec9 to your computer and use it in GitHub Desktop.
WP Custom Embed, to add responsive markup
// Modifica o html do video embebedado para ficar responsivo
add_filter( 'embed_oembed_html','oembed_result', 10, 3 );
function oembed_result( $html, $url, $args ) {
if( strstr( $url, 'youtu' ) ){
$video_pattern = '~(?:http|https|)(?::\/\/|)(?:www.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[a-z0-9;:@#?&%=+\/\$_.-]*~i';
$video_id = ( preg_replace( $video_pattern, '$1', $url ) );
$html = '<div class="video-container"><iframe src="https://www.youtube.com/embed/' . $video_id . '" frameborder="0" allowfullscreen';
foreach ( $args as $key => $value ) {
$html .= ' ' .$key . '="' . $value . '"';
}
$html .= '></iframe></div>';
} else {
$html = '<div class="video-container">' . $html . '</div>';
}
return $html;
}
function mg_youtube_player( $html, $url, $args ) {
return str_replace( '?feature=oembed', '?feature=oembed&modestbranding=1&showinfo=0&rel=0', $html );
}
add_filter( 'oembed_result', 'mg_youtube_player', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment