-
-
Save marco-s/2151809 to your computer and use it in GitHub Desktop.
oembed function to use content_width appropriately
This file contains hidden or 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
<?php | |
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