QR-Code using Google Chart API

This is a small little function to generate QR Codes for your site using the Google Chart API.

You can see an example on the sidebar of this site...

To use it just copy the following function to your theme's functions.php file.

To use the function in your theme just use:


function google_qr($url,$size ='150',$EC_level='L',$margin='0') {
$url = urlencode($url);
echo '<img src="https://chart.googleapis.com/chart?chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$url.'" alt="QR code" width="'.$size.'" height="'.$size.'"/>';
}

To use the function in your theme just use:


google_qr(url, size, ECLevel, margin);
// url is the URL for your QRCode
// size, size in pixels for image
// ECLevel, Error Correction Level
// margin, margin around image

Leave a Reply