短縮URLに変換した記事のリンクを設置する

Ads

Code

<?php
function getTinyUrl($url) {
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
return $tinyurl;
}
?>
/* テーマファイルには以下のように書く */
<?php
$turl = getTinyUrl(get_permalink($post->ID));
echo '短縮URL: <a href="'.$turl.'">'.$turl.'</a>'
?>
view raw gistfile1.aw hosted with ❤ by GitHub

Screen shot

Note

Description パーマリンクをtinyurl.comのAPIで短縮URLに変換してテーマファイル内に設置する
WordPress Ver. 3.3.1
Via Automatically provide tinyurls for your WordPress blog posts