Developers

How to add a QR code in WordPress without a plugin

To add a QR code in WordPress without a plugin, add an Image block, choose Insert from URL, and paste https://qrcodesforever.com/qr.svg?url= followed by your link. Or paste our HTML snippet into a Custom HTML block. There's nothing to install or keep updated, and the code holds your link directly, so it never expires.

How to do it

  1. 1

    Make the image link

    Start with https://qrcodesforever.com/qr.svg?url= and add your link, or make the code in our generator and copy the embed code.

  2. 2

    Add a block

    In the block editor, click + and add an Image block, or a Custom HTML block if you're pasting the embed code.

  3. 3

    Insert from URL

    In the Image block, choose Insert from URL, paste the image link and press Enter. Add alt text that says what the code does.

  4. 4

    Preview and scan

    Preview the page and scan the code with your phone before you publish.

A QR code plugin is one more thing to update and one more thing that can break on a WordPress upgrade. For a code that sits on a page, an image URL does the same job and survives theme changes.

The Custom HTML snippet

Paste this into a Custom HTML block, or a Custom HTML widget in a sidebar or footer:

<a href="https://qrcodesforever.com/">
  <img src="https://qrcodesforever.com/qr.svg?url=example.com"
       alt="QR code for example.com" width="200" height="200">
  <br>QR code by QR Codes Forever
</a>

Change example.com to your link. The surrounding link is optional credit; keep it if you're happy to. If your link contains &, ?, # or spaces, encode it first, or copy the embed code from the generator, which does that for you.

Other kinds of code

Swap the part after qr.svg?. The right-hand column is what each code holds:

After qr.svg?The code contains
ssid=Shop%20Guest&password=welcome123WIFI:T:WPA;S:Shop Guest;P:welcome123;;
type=whatsapp&whatsapp=919876543210&message=Hihttps://wa.me/919876543210?text=Hi
q=Your%20Shop%20Name%2C%20Citya Google Maps search for your shop
upi=shop@okaxis&amount=250upi://pay?pa=shop@okaxis&am=250.00&cu=INR

A Wi-Fi password in a public page's HTML is readable by anyone who views the source, so only post one for a guest network. Inside HTML, &amp; between parameters is the strictly valid form, though browsers accept a plain &. Full list: parameter reference.

A QR code on every post (PHP)

Add this to a child theme's functions.php to put a code at the end of every post, so readers on a computer can continue on their phone:

add_filter('the_content', function ($content) {
    if (!is_singular('post') || !in_the_loop() || !is_main_query()) {
        return $content;
    }
    $src = 'https://qrcodesforever.com/qr.svg?url=' . rawurlencode(get_permalink());
    $qr  = '<p><img src="' . esc_url($src) . '" alt="QR code for this post" width="140" height="140"></p>';
    return $content . $qr;
});

rawurlencode makes the permalink safe inside the image URL, and esc_url makes the whole URL safe inside HTML. A child theme keeps the filter from vanishing at the next theme update.

Weight and size

Our SVGs for short links come out around 11 KB. Denser codes weigh more: a contact card with a name, phone and email is about 49 KB. Each one is sent with a one-year cache header, so returning visitors don't download it again.

On screen, 150 to 250 pixels wide scans easily. For flyers printed from the page, the size calculator gives the printed size for the distance people will stand. The same image URL works in Notion and in plain HTML.

Questions people ask

Can I upload the SVG to the Media Library instead?

WordPress blocks SVG uploads by default, which is one reason linking by URL is easier. To host the file yourself, download the PNG from the generator and upload that.

Does this work on WordPress.com?

The Image block's Insert from URL option is part of the standard block editor, so it's the safe choice there. The PHP filter below needs a WordPress.com plan that allows custom code.

Written by Last updated