1

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?

1 Answer 1

4

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;
}
2
  • 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, 2011 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, 2011 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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