Use $content_width to Set Width of oEmbeds in WordPress

If you want resulting oEmbed code to scale to a specific size (width) in WordPress, you can do this really easily by setting the $content_width global variable before calling your oEmbed processing.


global $wp_embed, $content_width;
$content_width = '600'; // set to desired width
$string_with_embedded_content = $wp_embed->autoembed($string_with_oembed_url);

I only recently ran across this feature (just recently had the need for it), though it’s been around for at least a year. In talking with some other devs, it seems to not be a widely known feature – hopefully this helps.