2010/03/02

WordPress tip: Retweet shortcode

Tweetmeme はblog上に“Retweet”ボタンを示す人気が高いサービスである。single.phpファイルにコードを付け加えてボタンを表示することが簡単だとしても、投稿のどこにでも差し込むことができる shortcode を作ることは非常にクールだ。

shortcodeを作るためにはあなたのfunctions.phpファイルに次のコードを付け加える

function tweetmeme(){
 return '<div class="tweetmeme"><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>';
}
add_shortcode('tweet', 'tweetmeme');

shortcodeはポストのどこにでも Tweetmeme "retweet"ボタンを示すことができる。WordPressエディタをHTMLモードに変更して、表示したい場所に次のようにshortcodeを挿入する

[tweet]

ポストが表示されるとき自動的に、 shortcode[tweet] は TweetMeme ボタンに変わる。

原文:WordPress tip: Create a Tweetmeme “Retweeet” shortcode

0 件のコメント:

コメントを投稿