apply_filters( 'oembed_dataparse', string $return, object $data, string $url )

Filters the returned oEmbed HTML.


Description Description

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


Parameters Parameters

$return

(string) The returned oEmbed HTML.

$data

(object) A data object result from an oEmbed provider.

$url

(string) The URL of the content to be embedded.


Top ↑

Source Source

File: wp-includes/class-wp-oembed.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.9.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Maya Soloveva

    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.