Theme guide

How to add a PDF or file download to a Shopify product page

What you’ll need

  • The theme editor (to add a Custom Liquid block; no code editing)

    How to get this: The theme editor
    1. Online Store › Themes › Edit theme (on a copy of your theme if you want to test first).
    2. Add section or Add block › Custom Liquid, paste the code, then Save.

    Step-by-step guide (opens in a new tab)

  • Your settings for the feature (for example your free shipping amount or countdown end date)

Open the Liquid Snippet Studio

Step 1: make a File metafield for products

  1. Go to Settings › Metafields and metaobjects › Products, then click Add definition.
  2. Name it Download (PDF). Check that the namespace and key read custom.download_pdf (edit them if not); the code below uses that key.
  3. Select type File, keep One file, and make sure it accepts all file types, not only images, so PDFs can be picked.
  4. Click Save.

Step 2: attach the PDF to a product

  1. Open the product in Products.
  2. In the Metafields section, click Download (PDF), then upload the PDF or pick one you already put in Content › Files.
  3. Save the product.

Step 3: show a Download button

In Online Store › Themes › Customize, open a product, click Add block in Product information, choose Custom Liquid and paste this. Products without a file show nothing.

Download button (Custom Liquid block)
{%- assign file = product.metafields.custom.download_pdf.value -%}
{%- if file != blank -%}
  <p>
    <a class="button button--secondary" href="{{ file.url }}" target="_blank" rel="noopener">
      {{ file.alt | default: 'Download PDF' }}
    </a>
  </p>
{%- endif -%}

More than one file per product

Change the definition to List of files (or make a second definition, custom.downloads, as a list) and loop over the files instead:

Several downloads
{%- assign files = product.metafields.custom.downloads.value -%}
{%- if files != blank -%}
  <ul class="product-downloads">
    {%- for file in files -%}
      <li><a href="{{ file.url }}" target="_blank" rel="noopener">{{ file.alt | default: 'Download' }}</a></li>
    {%- endfor -%}
  </ul>
{%- endif -%}

Good to know

  • The link is Shopify’s CDN URL for the file (generic_file.url), so the PDF opens in the browser’s viewer. Most browsers ignore the download attribute on links to another domain, which is why the code opens it in a new tab instead.
  • Anyone with the link can open the file. For paid downloads (ebooks, patterns, software), use Shopify’s free Digital Downloads app instead, which emails a private link after purchase.
  • If you just want one PDF on one product, you can also paste the file’s link from Content › Files into the product description. The metafield way is better for many products: no code per product, and the button looks the same everywhere.
  • Search engines can index PDFs on your CDN. Give the file a descriptive name before you upload it, like linen-shirt-size-guide.pdf.

Questions

Where do I upload a PDF in Shopify?

In your admin, go to Content › Files and click Upload files. Shopify hosts it on its CDN; click the link icon next to the file to copy its URL.

Can I add a PDF to a Shopify product without an app?

Yes. Attach it with a product metafield of type File and show it with a Custom Liquid block in the product template, as on this page. An app is only needed if the PDF is something customers pay for.

Why doesn’t the Download button show on some products?

The block only shows when that product’s Download (PDF) metafield has a file. Check the product’s Metafields section, and that the metafield key in the code matches the definition (custom.download_pdf).

More guides