希望在 WordPress 的側欄顯示二維碼,自動對應當前頁面,發現 Simple QR Code Widget 這個外掛就是幹這個的,但因為是基於 Google Chart 做的,所以無法正常使用。

可以透過簡單的修改,讓他生效:

wp-content/plugins/qr-code-generator-widget/qrCode.php

function qrCodeGenerator( $width = '250', $height = '250', $url = null, $choe = 'UTF-8', $type = 'qr') {
if(empty($url)){
$url = get_permalink();
}
$title = get_the_title();

echo sprintf('%3$s', htmlspecialchars($url), $width, $title);
}

btw,可以搭配另外一款外掛 Display Widgets ,設定這個二維碼只在文章頁顯示。

更新:發現 Display Widgets 不支援第三方元件,我們可以透過程式碼來實現:

wp-content/plugins/qr-code-generator-widget/qrCode.php

function qrCode_widget($args) {

    // ...

    if( is_single() ) {

        echo $before_widget;
        echo $before_title;
        echo $options

['title'];
        echo $after_title;

        //Our Widget Content
        qrCodeGenerator( $options['height'], $options['width'], $options['uri'] );
        echo $after_widget;
    }  
}

2018-08-11T23:12:15+08:00發表於:2016-02-24|WordPress|