WordPress oEmbeds for TED videos

Add the following to your theme’s functions.php file

// Whitelist the TEDTalks oEmbed URL
wp_oembed_add_provider( 'http://www.ted.com/talks/*', 'http://www.ted.com/talks/oembed.json' );

function ted_shortcode( $atts ) {
    // We need to use the WP_Embed class instance
    global $wp_embed;

    // The "id" parameter is required
    if ( empty($atts['id']) )
        return '';

    // Construct the TEDTalk URL
    $url = 'http://www.ted.com/talks/view/lang/eng/id/' . $atts['id'];

    // Run the URL through the  handler.
    // This handler handles calling the oEmbed class
    // and more importantly will also do the caching!
    return $wp_embed->shortcode( $atts, $url );
add_shortcode( 'ted', 'ted_shortcode' );

Now, you can embed TEDTalks two ways:

  • [ted id=981] or
  • http://www.ted.com/talks/ze_frank_s_web_playroom.html


Tags: , ,

No comments yet.

Leave a Reply