Recently I needed to get oEmbed data for a video via an AJAX call for a lazy-load type of thing. I figured I should just use the built-in oEmbed support in WordPress and I searched (in vain) for some kind of API. Instead I was able to cobble together a quick function that returns the raw data I want from the endpoint.


 * Get the oEmbed data for a URL.
 * @param string $url URL to the resource.
 * @return bool|object False on failure or object with result from API.
function the_shipyard_get_oembed_result( $url ) {
    require ABSPATH . WPINC . '/class-oembed.php';
    if ( ! $url || empty( $url ) ) {
        return false;

    $oembed = _wp_oembed_get_object();
    $url = esc_url_raw( $url );
    $provider = $oembed->get_provider( $url );

    return $oembed->fetch( $provider, $url );

The fetch() method will return the object from an oEmbed request, which contains a bunch of data like the HTML for the iframe, a thumbnail image and various other bits and bobs. Try it out and see what you get back!

If you just need the HTML (the iframe for instance) you can use the get_html() method of the same class.