How to create a QR Codes plugin to add QR Codes to WordPress posts

Quick response codes are in short called as QR codes. It is very popular. QR code is very popular bar codes. It could encode up to 4296 characters within bar codes. Its principal characteristic is fast reading. Within very short space up to 4296 characters could be encoded. As compared to other bar codes QR code is popular because of its high ability to encode characters and smaller size. QR code application can perform numerous tasks all in one go. It takes a little time and information comes out from it very fast.

It helps immensely with product tracking while it is in logistics mode. Due to long distance logistics the single identification of products does take some time. It helps to identify it in no time. It helps in identifying products within the shortest possible of time. With the help of QR code scanner or with the help of QR code application in mobiles the product detection hardly takes any time. It helps in time tracking of logistics, document management in libraries and in office, general marketing and of course within website URLs which we are going to talk it and how to create a QR code plugin so that adding QR codes to word press articles becomes easier.

Bar codes are now commonly used in big shopping malls in payment counters. Tickets for entering into stadiums and for physical as well as tracking of items. It provides a well coordinated information management to all departments and that makes entire processing of information centralized. If you want to see how QR code is utilized in this website, just browse to the end of the article and then you should find the evidence of QR code out there and that could show the information about this article.
Some Precautions:

The first impression is that why we should create a plugin and why not installing the easy to use third party plugin. By creating the plugin all by yourself you provide simple coding infrastructure. Most of third party plugins do provide outer links and promotions and that should slow down your website considerably. For creating this plugin the code is simple. Too much of plugin does not slow down website but too much of presence of third party promotional links makes the website weird and connection to the server becomes difficult.

Secondly, by creating this plugin you would know about coding infrastructure as well as by implementing this in the form of coding even if you update theme this frame work remains as it is. IN this write up I would explain you about how to create a fully functional plugin for QR code so that it should be there at the end of every WordPress post and after scanning this you would find the heading of article and that could be opened in a new browser.

Always upload files such as plug in file from cPanel not from WordPress Admin. Always back up website so that in the case any difficulties you could make it to live once again. Open CPanel and log in to it. This tutorial is for self-hosted WordPress users. As WordPress dot come does not allow installation of plugins. Then go to File Manager and then wp-content and open it. Double click on wp-content and it should be open immediately. Go to Plugins and open it by double clicking on it.

How to create the Plugin Directory and Plugin File:

Here, we will use the name of plugin as ‘Awesome QR Code’ and it is your prerogative to rename it as per your conveniences and likings. In the plugins folder of cPanel add one folder to it. Right click on that folder and renames it to ‘awesome-qr-code’and save it. Remember the location of this folder to be inside Plugins folder. Open that folder named as ‘awesome-qr-code’ and here we should be adding two php files. One is ‘awesome-qr-code.php’ and the other one is ‘qrcode.php’

So first we login to cPanle and then files manager and then wp-content and then to Plugins and then within Plugins folder create a folder namely ‘awesome-qr-code’ and then within we create two php files namely ‘awesome-qr-code.php’ and the other one is ‘qrcode.php’. Still this time the contents within these two php files are empty and this means plugin is not working. In the following segment we would show you about what should have been the contents in these php files.


Select ‘awesome-qr-code.php’ and then click on Code Editor and the small dialogue box should open and then click on Edit to open it in a new browser tab. Paste the following code exactly within ‘awesome-qr-code.php’ and then save it.

Plugin Name: Awesome QR Code
Plugin URI:
Description: Adds QR Code to WordPress Posts
Version: 1.0
Author: mohan mekap
Author URI:
function qr_code($content)
 $url = get_permalink();

$qr = new qrcode();
 $html = "<p><b>QR Code:</b></p><p><img src='".$qr->get_link()."' border='0'/></p>";
 $content .= $html;

return $content;

add_filter("the_content", "qr_code");


Understanding ‘awesome-qr-code.php’:

include(“qrcode.php”); means we have to include this php file. I will write about this later on. This is the second php file that should be included within plugin folder and this php files calling to include the other php files in its wordpress set up.

function qr_code($content)
$url = get_permalink();

$qr = new qrcode();

$html = “<p><b>QR Code:</b></p><p><img src='”.$qr->get_link().”‘ border=’0’/></p>”;
$content .= $html;

return $content;

add_filter(“the_content”, “qr_code”);

This is the following code and here is the short explanation of this code. This function is meant to install QR code at the end of each WordPress post. So, this php function need to filter the entire post content and find out that here is end of the post and then add the HTML specific QR code image at the end of every WordPress post. Here inside this function the content filter is used to find the end of the article with the help of QR code to find out the permalink of the post from a data base, so that it should be shown before visitors see the entire article. Then it returns the entire content and returns the html to print that content to remove any such errors. The qr_code function is meant to filter function and find out the post content before the page output in a web browser.

Get_permalink is used to find out the permalink of post so that it should be embedded within QR code. The QR code image should be there from the other php files that has been there inside plugin. At last it is added at the end of content.


The second php file inside of ours plugin folder is ‘qrcode.php’. This script is developed by Arturs Sosins aka ar2rsawseen,


 * This script is developed by Arturs Sosins aka ar2rsawseen, 
 * Fee free to distribute and modify code, but keep reference to its creator 
 * This class generate QR [Quick Response] codes with proper metadata for mobile phones 
 * using google chart api 
 * Here are sources with free QR code reading software for mobile phones: 
 * For more information, examples and online documentation visit: 
class qrcode 
 private $data; 
 //creating code with link mtadata 
 public function link($url){ 
 if (preg_match('/^http:\/\//', $url) || preg_match('/^https:\/\//', $url)) 
 $this->data = $url; 
 $this->data = "http://".$url; 
 //creating code with bookmark metadata 
 public function bookmark($title, $url){ 
 $this->data = "MEBKM:TITLE:".$title.";URL:".$url.";;"; 
 //creating text qr code 
 public function text($text){ 
 $this->data = $text; 
 //creatng code with sms metadata 
 public function sms($phone, $text){ 
 $this->data = "SMSTO:".$phone.":".$text; 
 //creating code with phone 
 public function phone_number($phone){ 
 $this->data = "TEL:".$phone; 
 //creating code with mecard metadata 
 public function contact_info($name, $address, $phone, $email){ 
 $this->data = "MECARD:N:".$name.";ADR:".$address.";TEL:".$phone.";EMAIL:".$email.";;"; 
 //creating code wth email metadata 
 public function email($email, $subject, $message){ 
 $this->data = "MATMSG:TO:".$email.";SUB:".$subject.";BODY:".$message.";;"; 
 //creating code with geo location metadata 
 public function geo($lat, $lon, $height){ 
 $this->data = "GEO:".$lat.",".$lon.",".$height; 
 //creating code with wifi configuration metadata 
 public function wifi($type, $ssid, $pass){ 
 $this->data = "WIFI:T:".$type.";S:".$ssid.";P:".$pass.";;"; 
 //creating code with i-appli activating meta data 
 public function iappli($adf, $cmd, $param){ 
 $param_str = ""; 
 foreach($param as $val) 
 $param_str .= "PARAM:".$val["name"].",".$val["value"].";"; 
 $this->data = "LAPL:ADFURL:".$adf.";CMD:".$cmd.";".$param_str.";"; 
 //creating code with gif or jpg image, or smf or MFi of ToruCa files as content 
 public function content($type, $size, $content){ 
 $this->data = "CNTS:TYPE:".$type.";LNG:".$size.";BODY:".$content.";;"; 
 //getting image 
 public function get_image($size = 150, $EC_level = 'L', $margin = '0'){ 
 $ch = curl_init(); 
 $this->data = urlencode($this->data); 
 curl_setopt($ch, CURLOPT_URL, ''); 
 curl_setopt($ch, CURLOPT_POST, true); 
 curl_setopt($ch, CURLOPT_POSTFIELDS, 'chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
 curl_setopt($ch, CURLOPT_HEADER, false); 
 curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$response = curl_exec($ch); 
 return $response; 
 //getting link for image 
 public function get_link($size = 150, $EC_level = 'L', $margin = '0'){ 
 $this->data = urlencode($this->data); 
 return ''.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data; 
 //forcing image download 
 public function download_image($file){ 
 header('Content-Disposition: attachment; filename=QRcode.png'); 
 header('Content-Type: image/png'); 
 echo $file; 
 //save image to server
 public function save_image($file, $path = "./QRcode.png"){ 
 file_put_contents($path, $file);

Copy paste this code inside qrcode.php’ and you are done with creating a plugin that should show QR code of article permalink when a QR code scanners scan it.

How to activate ‘Awesome QR Code’:

Now, after completing the ‘Awesome QR Code’ plugin log out from cPanel. Open wp-admin the front end or the end of where you used to post the article and remove spam comments. From its side bar go to plugins and installed plugins. See the list of plugins there and you should find Awesome QR Code’ plugin and activate it.

You are done with it. Now, open article and browse at the end of the article and you should see the QR code of specific article. In this way, we have to create QR code plugin inside cPanel and then we activated it inside wp-admin and now we have completed the installation of QR Codes plug in to add QR Codes to WordPress posts.

Test your QR codes:

In order to scan and test QR code on mobile you need to install bar code scanner in your mobile operating system. If you have android then use popular BARCODE SCANNER.

If you have iOS then you can use RedLaser

Then open your website on computer or on another phone and then browse to the end of the article and then open bar code scanner app and then scan it and it should show the permalink of article and then click on it to open that link in web browser.


There are various important usages for QR codes. Due to this portability you can utilize it in term of spreading mobile probabilities of opening of web link all at once without any difficulties. From this tutorial above it is seen that it is very easy to use and do not require any rocket science in it. If you wish to create a project or something then you could easily embedded this as this works with Google api and for this it always stays in on live conditions and the image of QR code always comes out and in addition while printing of this article you could find that the QR code image also printed to provide the most specific authenticity of yours presence.

You would never know at any point of time Google could implement this policy for better search engine optimization formulations and for this it is important to go ahead and implement all with yours own and without depending upon others by creating this plugin as it could provide more and more easier ways to understand the indexing due to presence of QR code readabilities in automation processes by computers and servers.

*A few days ago. I read a post on which discussed ‘How to Add QR Codes to WordPress Posts’. I’d never hear of this before, but I was intrigued, so I read on.*

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *