WordPress.org

Ready to get started?Download WordPress

Forums

filter hook for built-in oEmbed providers (e.g. youtube) (6 posts)

  1. nootron
    Member
    Posted 4 years ago #

    I am looking for a way to add the title of a youtube video ABOVE the embedded youtube code when using oEmbed functionality in wordpress.

    I am also open to using the [embed] shortcode and add custom title attribute there.

    Ive been tearing my hear out all day trying to get a working function filter for oembed that can read custom attributes or custom values from the returned xml/json.

    Any ideas?

    Im currently trying to access the $data object from the filter hook: oembed_dataparse:

    // You can use this filter to add support for custom data types or to filter the result
    return apply_filters( 'oembed_dataparse', $return, $data, $url );

    But I am not having any success.

  2. nootron
    Member
    Posted 4 years ago #

    Just by posting my question, i was somehow able to figure this out.

    Here's an example.

    $foo = new ExampleWrapper_Oembed;
    
    class ExampleWrapper_Oembed {
    	/* Here's our filter function. */
    	function add_wrapper( $return, $data, $url ) {
        	/*
            	$data is an object created by the xml/json returned from the original oEmbed request. 
    
                Some other youtube fields:
                http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D-UUx10KOWIE&format=xml
    
                Each oembed provider will have different fields here, so check oembed.com for specifics:
                http://www.oembed.com/
    
            */
    
        	/* So lets check for the youtube video title. */
    		if( strlen($data->title) > 0 )
    			return $titlebar = '<div class="title">' . $data->title . '</div>' . $return;
    			// we found one, so create some html and prepend it to $result which is the resulting html output.
    
    		return $return;
    	}
    
        /* adding the filter function to the oembed_dataparse filter hook */
    	function ExampleWrapper_Oembed() {
    		add_filter('oembed_dataparse', array(&$this,'add_wrapper'), 10, 3);
    	}
    }
  3. saphod
    Member
    Posted 4 years ago #

    Hi notroon,

    since you tried something similar as I do, maybe you can help me out. Did your code actually work?

    If so, I'd be glad if you could have a look at my problem here:
    http://wordpress.org/support/topic/416648

    Thanks!

  4. saphod
    Member
    Posted 4 years ago #

    I managed to achive my task by using the embed_oembed_html-filter - see http://wordpress.org/support/topic/416648.

    Thanks, anyway! :-D

  5. Armin Ro?u
    Member
    Posted 3 years ago #

    Thanks saphod, I tried a bunch too, and only embed_oembed_html worked.

    Thanks mate!

  6. thinkunique
    Member
    Posted 3 years ago #

    nootron, if you're still there, can you help me with implementing the code you posted? I can't get it to work-- nothing gets added to the wrapper. Where am I supposed to add the code you added?

    -Peter.

Topic Closed

This topic has been closed to new replies.

About this Topic