> For the complete documentation index, see [llms.txt](https://wishlist.nativeappco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wishlist.nativeappco.com/install-and-setup/theme-setup/add-code-snippet-to-collection-grid.md). Agents can also search and read this documentation through its [MCP server](https://wishlist.nativeappco.com/~gitbook/mcp).

# Add code snippet to collection grid

Insert our code snippet to your product grid item to add our wishlist buttons to your collection grid.

Add the wishlist icon to the product cards on your collection, search and recommendation grids.

{% hint style="info" %}
This requires some edits to your theme code. If you need help, please [Contact Us](mailto:undefined).
{% endhint %}

## Instructions

1. **Access Your Theme Files**:
   * In your Shopify admin, go to **Online Store** > **Themes**.
   * Find your published theme, and click **Actions** > **Edit Code**.
2. **Locate Your Product Card Code**:
   * Open the snippet that renders one product card. It's usually in the **Snippets** folder, with a name like `card-product.liquid`, `product-card.liquid` or `product-grid-item.liquid`.
   * Use the shared card snippet rather than each section, so collections, search and recommendations all get the icon.
3. **Find the Product Variable**:
   * Look at how the card prints the product's title or URL, for example `{{ card_product.title }}` or `{{ product.url }}`. The word before the dot (`card_product`, `product`, `item`...) is the product variable you'll use in the next step.
4. **Insert the Wishlist Button Code**:
   * Paste this inside the card's image wrapper, replacing `card_product` with your product variable if it's different:

     ```liquid
     <wishlist-button class="position-absolute top-right" data-variant-id="{{ card_product.variants | map: 'id' | join: ',' }}"></wishlist-button>
     ```
   * `data-variant-id` must list all of the product's variant IDs, separated by commas, as the code above does. Products with several variants open a variant picker when the icon is clicked; single-variant products are saved straight away.
5. **Adjust Button Positioning** (Optional):
   * Replace `top-right` in the `class` with one of:
     * **`top-right`**: Top right corner (default).
     * **`top-left`**: Top left corner.
     * **`bottom-right`**: Bottom right corner.
     * **`bottom-left`**: Bottom left corner.
   * The button is positioned inside the closest element that has `position: relative`. If it shows up in the wrong place, add `position: relative` to the card's image wrapper.
6. **Save and Preview**:
   * Click **Save** after making changes.
   * Preview a collection page and check the icon appears on each card, and that clicking it saves the product.

<figure><img src="https://1134778209-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMp2ekCAtVgFUnsQlGWfX%2Fuploads%2Fqk95YrS3LTPuCgSUiLRb%2Fimage.png?alt=media&amp;token=74fb98ba-1329-46f9-9c76-662b82f35b8c" alt="Wishlist icons on product cards in a collection grid"><figcaption></figcaption></figure>

{% hint style="warning" %}
**Icon does nothing when clicked?** Open your browser's console. `Fish Wishlist Error: Incorrect variant id on wishlist button` means `data-variant-id` is empty: the product variable in your snippet isn't the one your card uses (step 3).
{% endhint %}

### Search and filter apps

Apps such as Algolia, Searchspring or Boost often build their product cards in JavaScript instead of your theme's Liquid snippet, so the code above won't run there. Add the same element to the app's card template, with `data-variant-id` set to the product's variant IDs separated by commas, for example:

```html
<wishlist-button class="position-absolute top-right" data-variant-id="44123456789012,44123456789013"></wishlist-button>
```

Use the app's own field for the variant IDs (check its template documentation). Buttons added to the page later work on their own; no extra script is needed.
