Sunday, October 21, 2012

Add QR Codes to your Printed Blog Pages

This nifty trick comes courtesy of labnol.
For Wordpress, paste the following before the </head> tag in either header.php or index.php:
<?php if (is_single()) : ?> <style type="text/css"> @media print { body:after { content:url ( http://chart.googleapis.com/chart?cht=qr&chs=200x200&choe=UTF-8&chld=H&chl=<?= the_permalink(); ?>) } } </style> <?php endif; ?>

For Blogger, the instructions sound a bit more complex ("if you are using the new XML based Blogger templates, you probably need to use data:blog.canonicalUrl for the permalink with the condition set as since we are only displaying QR codes on individual post pages and not the archives"), but the code is similar:

<ItemPage><Blogger> <style type="text/css"> @media print { body:after { content:url ( http://chart.googleapis.com/chart?cht=qr&chs=200x200&choe=UTF-8&chld=H&chl=<$BlogItemPermalinkURL$>) } } </style> </Blogger></ItemPage>

I have yet to implement it and test it - at which point I might modify this text. However, I thought this is way too nice to keep just for myself. Enjoy and see the original below!
Sources / More Info: labnol

No comments:

Post a Comment

Thank you for commenting and rest assured that any and all comments are welcome, whether positive or negative, constructive or distructive. Unfortunately, if you comment in this view I might not know about - please use the regular (Desktop) view.
I am using Disqus for commenting, but Blogger is not showing it so your comments may end up not being displayed - tell Google about it!