Created
March 12, 2018 17:12
-
-
Save tacensi/6e0aa230af3e8256c455c7a2db7b9ec9 to your computer and use it in GitHub Desktop.
WP Custom Embed, to add responsive markup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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