js 做法:qrcodejs
不怎么推荐这个的原因是因为现在生成的二维码是canvas或者table格式的,手机上无法识别二维码,当然你也可以再用另外的js把canvas转成二维码。
1 |
<div class="project-qrcode"></div> |
1 2 3 4 5 6 |
jQuery(".project-qrcode").qrcode({ render: 'canvas', width: 180, height: 180, text: wechat_href }); |
php 做法:phpqrcode
只提供一个自己用在wordpress下的写法:在本地生成了一张图片,然后调用这张图片;也有很多写法用data-image的二维码。
输出二维码的地方
1 |
<?php echo getqrcode_base64($link, $post->ID);?> |
function.php 加入以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function getqrcode_base64($url, $slug) { $errorCorrectionLevel = 'L'; //容错级别 $matrixPointSize = 10; //生成图片大小 //生成二维码图片 $filename = WP_CONTENT_DIR.'/qrcode/qrcode-'.$slug.'.png'; QRcode::png($url,$filename , $errorCorrectionLevel, $matrixPointSize, 2); $QR = $filename; //已经生成的原始二维码图片文件 $QR = imagecreatefromstring(file_get_contents($QR)); //输出图片 return '<img src="'.content_url().'/qrcode/qrcode-'.$slug.'.png" alt="">'; } |