apply_filters( ‘oembed_dataparse’, string $return, object $data, string $url )

Filters the returned oEmbed HTML.

Description

Use this filter to add support for custom data types, or to filter the result.

Parameters

$returnstring
The returned oEmbed HTML.
$dataobject
A data object result from an oEmbed provider.
$urlstring
The URL of the content to be embedded.

Source

return apply_filters( 'oembed_dataparse', $return, $data, $url );

Changelog

VersionDescription
2.9.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Can be used to wrap oEmbed response in html, depending on type and size of oEmbed.

    function wrap_oembed_dataparse($return, $data, $url) {
    
    	$mod = '';
    
    	if  (   ( $data->type == 'video' ) &&
    			( isset($data->width) ) && ( isset($data->height) ) &&
    			( round($data->height/$data->width, 2) == round( 3/4, 2) )
    		)
    	{
    		$mod = 'embed-responsive--4-3';
    	}
    
    	return '<div class="embed-responsive ' . $mod . '">' . $return . '</div>';
    }
    
    add_filter( 'oembed_dataparse', 'wrap_oembed_dataparse', 99, 4 );

    To use ‘oembed_dataparse’ for the first time, you might have to clear oEmbed post-meta cache:

    add_filter( 'oembed_ttl', function($ttl) {
    	  $GLOBALS['wp_embed']->usecache = 0;
                $ttl = 0;
                // House-cleanoing
                do_action( 'wpse_do_cleanup' );
    	return $ttl;
    });
    
    add_filter( 'embed_oembed_discover', function( $discover )
    {
        if( 1 === did_action( 'wpse_do_cleanup' ) )
            $GLOBALS['wp_embed']->usecache = 1;
        return $discover;
    } );

You must log in before being able to contribute a note or feedback.