Walker News

Simple WordPress QR Code Plugin To Create 2D Barcode Of Each Post Page

I’ve just developed this simple WordPress QR Code plugin for those who are interested to generate and display individual QR Code of each post and page on a self-hosting, WordPress-powered blog.

There is no PHP file to “install” in the plugins directory. You neither have option to configure nor to activate or deactivate the said plugin in Manage Plugins page of dashboard.

All you have to do is edit the functions.php file of the active WordPress theme and append the following PHP code at the end of file content (create the functions.php file, in case it is not exist in your active WordPress theme):
<?php
add_filter('the_content', 'wn_add_qr_code');

function wn_add_qr_code ($rawcontin){

        global $id;
        $wn_postlink = get_permalink($id);

        $rawcontin = '<img style="float:left;margin:0px 0px 0px 0px;" src="http://chart.apis.google.com/chart?cht=qr&chs=60x60&chl=' . $wn_postlink . '" alt="" width="60" height="60" />' . $rawcontin;

        return $rawcontin;
}
?>

The said plugin is activated automatically after saving the change in functions.php file. To deactivate this simple WordPress QR Code plugin (in my view), just delete the appended block of code will do.

WordPress QR Code plugin that can create and display QR Code of each post on the fly while the page is loading.

If you would like to further customize the appearance of QR Code appears in the post page, you can do so by tweaking CSS properties of IMG tag or change the text in red (60×60, value of width and height respectively) should you prefer a different QR Code image size.
I can’t figure out how to precisely display the QR Code next to post title. If you would like the 2D barcode appears in such a way, please refer to previous post.

The plugin, as shown, make use of Google Chart API to create and display individual QR Code of each blog post URL, on the fly while the page is loading. Hence, there is no need to pre-create the QR code and host it at web server for display.

It will work until the Google Chart API stops to allow free access by public. Since the displayed QR Code is fixed size, with respect to the width and height properties of IMG tag, there should be no much interruption to the layout of post page should the Google Chart API stops working. By then, just “deactivate” the plugin :-)

Custom Search

  1. Walker 06-03-10@18:00

    NOTE:

    If the functions.php template file exist in your active theme directory,

    1. Copy that block of code but EXCLUDE the 1st and last line, i.e. <?php and ?>
       
    2. INSERT the copied code in the existing functions.php, in between the <?php and ?> tags.
  2. Jesse Luna 27-02-11@02:35

    Very nice! I added a modified version to my Single Post template page in order to better position the QR code image.

2017  •  Privacy Policy