X

How To Generate QR Code for Posts and Pages

Snippets by IsItWP

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?

Comments   Leave a Reply

  1. can anyone that tried this share a page/post to see how it works??

    1. 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.

  2. syntax error could you post the code the way its to be placed in the PHP file

    1. 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/

  3. 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..

  4. This is good!

  5. This is good!

  6. This is good!

  7. Thank You

  8. why should I generate a QR-code for a page/post I’m already on?

    1. 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.

  9. Great tip, thank you!

  10. Very useful, thanks for sharing

  11. How to automatically generate a QR code for your posts July 9, 2012 at 10:12 am

    […] to Kevin Chard for the tip! If you enjoyed this article, please consider sharing it! tweetmeme_style = […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!