Have you ever wanted to generate a Quick Response code (QR code) for a post or page of your WordPress website? This snippet will render a QR-code for every article.
Instructions:
Add this small snippet to the single.php file of your WordPress theme inside the Loop at the location you wish to display the QR code. To adjust the size of the QR image, just change the following within the src
attribute: size=100x100
. For example, to make a image that is 200px by 200px, change the value to size=200x200
.
<img src="http://api.qrserver.com/v1/create-qr-code/?size=100x100&data=<?php the_permalink(); ?>" alt="QR: <?php the_title(); ?>"/>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: What is a Blog? Blog vs. Website & How Do They Work?
can anyone that tried this share a page/post to see how it works??
It works by getting an image from this link: http://api.qrserver.com/v1/create-qr-code/?size=100×100&data=
The
data
value of the query string needs to have the permalink added to it in order to work, as shown in the snippet.syntax error could you post the code the way its to be placed in the PHP file
You may want to check out this guide on adding code snippets, as the code can be pasted in many ways inside a theme template file: https://www.isitwp.com/properly-add-code-snippets-wordpress-site/
Runned into this site a few day’s ago and are always carefull with registering and commenting else where. But i have to admit that this is a great recource for learing and understanding php. Thanks and keep up this knowledgebase..
This is good!
This is good!
This is good!
Thank You
why should I generate a QR-code for a page/post I’m already on?
For example, you’re using a page from your PC & with the QR Code, you can easily open the page on your phone without typing the url. Also helps in sharing post to sites.
Great tip, thank you!
Very useful, thanks for sharing
[…] to Kevin Chard for the tip! If you enjoyed this article, please consider sharing it! tweetmeme_style = […]