記事内にショートコードでQRコードを含める

Ads

Code

<?php
function add_qrcode_in_this_article($atts) {
extract(shortcode_atts(array(
'url' => 'http://example.com',
'size' => '80',
), $atts));
return '<img src="https://chart.googleapis.com/chart?chs=' . $size . 'x' . $size . '&cht=qr&chl=' . $url . '&choe=UTF-8 " alt="QR Code"/>';
}
add_shortcode('myqrcode', 'add_qrcode_in_this_article');
?>
/*ショートコードは [myqrcode url="http://foo.net" size="150"] と書く。*/
view raw gistfile1.aw hosted with ❤ by GitHub

Screen shot

Note

Description ショートコードでサイズとURLを指定。Google APIを使う。
WordPress Ver. 3.3.1
Via URLやサイズを指定出来るQRコードをショートコードで作れるようにする