oEmbed 対応 ショートコード

ショートコード
投稿には、以下のように記述します

[youtube id="nmanjsjp4AU" width="300" height="200" /]

3.01 functions.php

add_shortcode( 'youtube', 'my_youtube_shortcode' );
function my_youtube_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 YouTube URL
	$url= 'http://www.youtube.com/watch?v=' . $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 );
}

http://www.viper007bond.com/2010/06/23/creating-simple-oembed-based-wordpress-shortcodes/


oEmbed を使ったタグの自動挿入は、ベーシックなショートコードが用意されています。
以下のように記述することで、同様の表現が可能です。関数などの登録の必要はありません。

以下のようなショートコードを記述することで

[embed width=”200″ height=”150″]http://www.youtube.com/watch?v=nmanjsjp4AU\[/embed]

以下のソースが組み立てられます。

http://www.youtube.com/watch?v=nmanjsjp4AU\

[emulsion_relate_posts]