Revision 357 is a pre-publication revision. (Viewing current revision instead.)

WordPress oEmbeds for TED videos

Add the following to your theme's functions.php file [php]// 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' );[/php] Now, you can embed TEDTalks two ways:
  • [ted id=981] or
  • http://www.ted.com/talks/ze_frank_s_web_playroom.html

Revisions

  • February 14, 2013 @ 12:30:46 [Current Revision] by PeterLugg
  • February 14, 2013 @ 12:28:52 by PeterLugg

Revision Differences

February 14, 2013 @ 12:28:52Current Revision
Content
Unchanged: Add the following to your theme's functions.php fileUnchanged: Add the following to your theme's functions.php file
Unchanged: [php]// Whitelist the TEDTalks oEmbed URLUnchanged: [php]// Whitelist the TEDTalks oEmbed URL
Unchanged: wp_oembed_add_provider( 'http://www.ted.com/talks/*', 'http://www.ted.com/ talks/oembed.json' );Unchanged: wp_oembed_add_provider( 'http://www.ted.com/talks/*', 'http://www.ted.com/ talks/oembed.json' );
Unchanged: function ted_shortcode( $atts ) {Unchanged: function ted_shortcode( $atts ) {
Unchanged: // We need to use the WP_Embed class instanceUnchanged: // We need to use the WP_Embed class instance
Unchanged: global $wp_embed;Unchanged: global $wp_embed;
Unchanged: // The "id" parameter is requiredUnchanged: // The "id" parameter is required
Unchanged: if ( empty($atts['id']) )Unchanged: if ( empty($atts['id']) )
Unchanged: return '';Unchanged: return '';
Unchanged: // Construct the TEDTalk URLUnchanged: // Construct the TEDTalk URL
Unchanged: $url = 'http://www.ted.com/ talks/view/lang/eng/id/' . $atts['id'];Unchanged: $url = 'http://www.ted.com/ talks/view/lang/eng/id/' . $atts['id'];
Unchanged: // Run the URL through the handler.Unchanged: // Run the URL through the handler.
Unchanged: // This handler handles calling the oEmbed classUnchanged: // This handler handles calling the oEmbed class
Unchanged: // and more importantly will also do the caching!Unchanged: // and more importantly will also do the caching!
Unchanged: return $wp_embed->shortcode( $atts, $url );Unchanged: return $wp_embed->shortcode( $atts, $url );
Unchanged: }Unchanged: }
Unchanged: add_shortcode( 'ted', 'ted_shortcode' );[/php]Unchanged: add_shortcode( 'ted', 'ted_shortcode' );[/php]
 Added: Now, you can embed TEDTalks two ways:
 Added: <ul>
 Added: <li>[ted id=981] or</li>
 Added: <li>http://www.ted.com/ talks/ze_frank_ s_web_playroom.html</li>
 Added: </ul>

Note: Spaces may be added to comparison text to allow better line wrapping.

Tags: , ,

No comments yet.

Leave a Reply