Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to add oEmbed DeviantArt integration to a custom theme.

I found that first step is quite easy, I added

wp_oembed_add_provider( 'http://*.deviantart.com/#/d*', 'http://backend.deviantart.com/oembed' );   

to theme's functions.php.

Now, I would like to change the default HTML output to add more information, available in DeviantArt JSON response (DeviantART reference), like author_name, author_url, etc.

If I have studied well the WP code that manage the output is inside function data2html in class-oembed.php, but I don't like change the code here.

How can I add a function to my theme, to achieve the desired result?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

WP_oEmbed::data2html() has a filter, oembed_dataparse. You can use this to change the output, based on the extra data which is passed as the second parameter.

Something like this for example:

add_filter( 'oembed_dataparse', 'wpse17461_oembed_dataparse', 10, 3 );
function wpse17461_oembed_dataparse( $html, $data, $url )
{
    if ( FALSE !== strpos( $url, 'deviantart.com' ) ) {
        return $html . '<br/>Author: ' . $data->author_name;
    }
    return $html;
}
share|improve this answer
    
Thank you very much. Just a note, your code generate an error, maybe causes by my environment. I fixed it using: return $html . '<br/>Author: ' . $data->author_name; –  Drake May 17 '11 at 15:39
    
@Drake: Ah, indeed, I did not test it, so I did not know whether $data was an array or an object. I corrected it, thanks. –  Jan Fabry May 17 '11 at 15:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.