Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
oembed function to use content_width appropriately
function yoast_oembed_dataparse( $html, $data, $url ) {
global $content_width;
preg_match( '/width="(\d+)"/', $html, $matches );
$width = $matches[1];
preg_match( '/height="(\d+)"/', $html, $matches );
$height = $matches[1];
$aspect_ratio = $width / $height;
$new_height = $content_width / $aspect_ratio;
$html = str_replace( 'width="'.$width.'"', 'width="'.$content_width.'"', $html );
$html = str_replace( 'height="'.$height.'"', 'height="'.$new_height.'"', $html );
return $html;
add_filter( 'oembed_dataparse', 'yoast_oembed_dataparse', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment