Create QR Codes For Your WordPress Posts

QR Code are make many things easier to be used on mobile devices. User could simply to scan the QR Code for getting the web site URL, basic information, etc.

How to make your every dynamic web pages to have their own QR Code? Especially on CMS platform, such as WordPress. All content posts/pages doesn’t really exist on the Web Server. All of them are being generated by the platform Server-side programs, mixed with several values on the databases and themes modules. It is not easiler to got the job done.

A little bit Theme Hacking and ShortCode being called by PHP

The simple way to archive the goal is simply modify several PHP files on your WordPress site.

1. Functions.php

Append the following Function and ShortCode declaration on the functions.php Theme files.

function currentpage_qr_code( $atts ) {
    extract(shortcode_atts(array(
        'size' => '300'
    ), $atts)); 

    global $post;  

    return '<img src="http://api.qrserver.com/v1/create-qr-code/?size='.$size.'x'.$size.'&amp;data='.get_permalink( $post->ID ).'" alt="'.$post->post_title.'"/>';  

}
add_shortcode('currentqr', 'currentpage_qr_code');

Sure, you can modify the function name, ShortCode name and the size value you want to fit for your Web Site.

Nornally, you can use the ShorCode (Default: currentqr) on Page/Post immediately after you have save the function.php file.

2. Single.php, Page.php

The trouble might come out now, too much Pages and Posts requires to be modified. Add this ShortCode is extremly easy but extremly cost your time also.

The best way is modify two Theme Template Fles for Post and Pages. Spend a little bit time to seek for a right place to use the ShortCode on the Theme Template Files, then you can save your time to out for a tea-break.

Common location to place the ShortCode calling may near the Comment Element on the target Theme Template Files.

3. How to call ShortCode on PHP file?

The next problem might come out after you have choose a right place on the Theme Template file. In fact, ShortCode are originally designed for Post/Page content editing area. How to execute the ShortCode on the Theme Template Files?

All Theme Template Files are PHP files. You can use WordPress specific PHP function call to do a ShortCode call action.

The syntax has shown below.

<?php
echo do_shortcode('[currentqr]');
?>

You can mixed with other HTML coding with this ShortCode execution to make it to fit for other layout formatting concerns or CSS style apply.

Reference

This content were referenced to the following web page:
http://www.paulund.co.uk/create-qr-codes-for-your-wordpress-posts

The QR-Code generator API are provided by QR-Serve, which belongs to DENSO WAVE INCORPORATED:
http://goqr.me

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

活動

次の記事

再回到母校