Debian Codegraph @

docs/content/en/shortcodes/qr.md

raw
1 ---
2 title: QR shortcode
3 linkTitle: QR
4 description: Insert a QR code into your content using the qr shortcode.
5 categories: []
6 keywords: []
7 ---
8
9 {{< new-in 0.141.0 />}}
10
11 > [!NOTE]
12 > To override Hugo's embedded `qr` shortcode, copy the [source code][] to a file with the same name in the `layouts/_shortcodes` directory.
13
14 The `qr` shortcode encodes the given text into a [QR code][] using the specified options and renders the resulting image.
15
16 Internally this shortcode calls the `images.QR` function. Please read the [related documentation][] for implementation details and guidance.
17
18 ## Examples
19
20 Use the self-closing syntax to pass the text as an argument:
21
22 ```md
23 {{</* qr text="https://gohugo.io" /*/>}}
24 ```
25
26 Or insert the text between the opening and closing tags:
27
28 ```md
29 {{</* qr */>}}
30 https://gohugo.io
31 {{</* /qr */>}}
32 ```
33
34 Both of the above produce this image:
35
36 {{< qr text="https://gohugo.io" class="qrcode" targetDir="images/qr" />}}
37
38 To create a QR code for a phone number:
39
40 ```md
41 {{</* qr text="tel:+12065550101" /*/>}}
42 ```
43
44 {{< qr text="tel:+12065550101" class="qrcode" targetDir="images/qr" />}}
45
46 To create a QR code containing contact information in the [vCard][] format:
47
48 ```md
49 {{</* qr level="low" scale=2 alt="QR code of vCard for John Smith" */>}}
50 BEGIN:VCARD
51 VERSION:2.1
52 N;CHARSET=UTF-8:Smith;John;R.;Dr.;PhD
53 FN;CHARSET=UTF-8:Dr. John R. Smith, PhD.
54 ORG;CHARSET=UTF-8:ABC Widgets
55 TITLE;CHARSET=UTF-8:Vice President Engineering
56 TEL;TYPE=WORK:+12065550101
57 EMAIL;TYPE=WORK:[email protected]
58 END:VCARD
59 {{</* /qr */>}}
60 ```
61
62 {{< qr level="low" scale=2 alt="QR code of vCard for John Smith" class="qrcode" targetDir="images/qr" >}}
63 BEGIN:VCARD
64 VERSION:2.1
65 N;CHARSET=UTF-8:Smith;John;R.;Dr.;PhD
66 FN;CHARSET=UTF-8:Dr. John R. Smith, PhD.
67 ORG;CHARSET=UTF-8:ABC Widgets
68 TITLE;CHARSET=UTF-8:Vice President Engineering
69 TEL;TYPE=WORK:+12065550101
70 EMAIL;TYPE=WORK:[email protected]
71 END:VCARD
72 {{< /qr >}}
73
74 ## Arguments
75
76 `text`
77 : (`string`) The text to encode, falling back to the text between the opening and closing shortcode tags.
78
79 `level`
80 : (`string`) The error correction level to use when encoding the text, one of `low`, `medium`, `quartile`, or `high`. Default is `medium`.
81
82 `scale`
83 : (`int`) The number of image pixels per QR code module. Must be greater than or equal to 2. Default is `4`.
84
85 `targetDir`
86 : (`string`) The subdirectory within the [`publishDir`][] where Hugo will place the generated image.
87
88 `alt`
89 : (`string`) The `alt` attribute of the `img` element.
90
91 `class`
92 : (`string`) The `class` attribute of the `img` element.
93
94 `id`
95 : (`string`) The `id` attribute of the `img` element.
96
97 `loading`
98 : (`string`) The `loading` attribute of the `img` element, either `eager` or `lazy`.
99
100 `title`
101 : (`string`) The `title` attribute of the `img` element.
102
103 [QR code]: https://en.wikipedia.org/wiki/QR_code
104 [`publishDir`]: /configuration/all/#publishdir
105 [related documentation]: /functions/images/qr/
106 [source code]: <{{% eturl qr %}}>
107 [vCard]: <https://en.wikipedia.org/wiki/VCard>