Skip to content

Instantly share code, notes, and snippets.

@marco-s
Forked from jdevalk/gist:1565059
Created March 21, 2012 19:35
Show Gist options
  • Save marco-s/2151809 to your computer and use it in GitHub Desktop.
Save marco-s/2151809 to your computer and use it in GitHub Desktop.
oembed function to use content_width appropriately
<?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