Answering a question from one of my blog visitors , Asheesh. He asked, how to create a QR code image after doing a published content WordPress. I have tried to make the code in WordPress themes. Hopefully, can solve the problem.
With a WordPress action hook, namely publish_post, after doing publish a new article, WordPress will establish a QR code image and stored it in the folder on the theme.
To make the QR code generator process , you can read through my previous article How to Build QR Code Generator Site With PHP QR CODE library. I don’t understand what the goal he creates these script. But, just started following tutorials
How to create QR code image after do published an article on WordPress blog
- Make sure you have downloaded the phpqrcode library.
- Create a folder in your WordPress theme and name “qrcode“. Don’t forget to change the permissions of the folder be 777 or 755. In this example, I am using a Twenty Fifteen theme.
- Copy the phpqrcode folder to qrcode folder.
- Add the following code in the function.php in your WordPress theme
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function post_published_notification( $ID, $post ) { $permalink = get_permalink( $ID ); include get_template_directory().'/qrcode/phpqrcode/qrlib.php'; define('EXAMPLE_TMP_SERVERPATH', get_template_directory().'/qrcode/'); define('EXAMPLE_TMP_URLRELPATH', get_template_directory().'/qrcode/'); $tempDir = EXAMPLE_TMP_SERVERPATH; $codeContents = $permalink; $fileName = $post->post_title.'.png'; $pngAbsoluteFilePath = $tempDir.$fileName; $urlRelativeFilePath = EXAMPLE_TMP_URLRELPATH.$fileName; if (!file_exists($pngAbsoluteFilePath)) { QRcode::png($codeContents, $pngAbsoluteFilePath); } } add_action( 'publish_post', 'post_published_notification', 10, 2 ); |
Save it and please see the result by adding a new post. If you are successful. then it will get the results as shown below.
Besides to show permalink on QR Code image, you can add additional information such as author, name,email, title with the following codes
1 2 3 4 | $author = $post->post_author; /* Post author ID. */ $name = get_the_author_meta( 'display_name', $author ); $email = get_the_author_meta( 'user_email', $author ); $title = $post->post_title; |
So my article about How To Create QR CODE Image After Published New Article WordPress. Hope useful
Leave a Reply