Skip to content

Instantly share code, notes, and snippets.

@carolineschnapp
Last active June 21, 2021 20:44
Show Gist options
  • Save carolineschnapp/ea569a4f1818ca1d32b9 to your computer and use it in GitHub Desktop.
Save carolineschnapp/ea569a4f1818ca1d32b9 to your computer and use it in GitHub Desktop.
SwiftType snippet
<!-- It is important to understand that SwiftType uses Shopify's robots.txt to know which pages to crawl for suggestions.
So it will look at 'page' pages, blog pages, collection pages and product pages.
It will also crawl the home page and /serach page unless those are deleted in the SwiftType account under Pages.
It will look at collection-agnostic product URLs, because that's what robots.txt tells it to do.
So no collection-aware product pages will be crawled. -->
<!-- Other important consideration: as title for the suggestion, SwiftType uses the content of the title tag, or any h1 or h2 tags, on the page.
For most searches, the content title will show up nicely: product title if searching for a product, collection title if searching for a collection, etc.
Since Shopify 2, one can set up a SEO title for each product, and we don't want it to come up, so we can force a few things for product pages:
product title, also add vendor name, product type, product tags, and product image...-->
<!-- Product results are by far the most important to suggest, so we are setting the priority to 2. Default is 1. -->
{% if template contains 'product' %}
<meta property='st:title' content='{{ product.title | strip_html | escape }}' />
<meta property='st:section' content='{{ product.vendor | strip_html | escape }}' />
<meta property='st:section' content='{{ product.type | strip_html | escape }}' />
{% for tag in product.tags %}
<meta property='st:section' content='{{ tag | escape }}' />
{% endfor %}
<meta property='st:image' content='{{ product.featured_image | product_img_url: "thumb" }}' />
<meta property='st:popularity' content='2' />
{% endif %}
{% if template contains 'collection' %}
<meta property='st:title' content='{{ collection.title | strip_html | escape }}' />
{% if collection.image %}
<meta property='st:image' content='{{ collection.image | collection_img_url: "thumb" }}' />
{% endif %}
{% endif %}
@carolineschnapp
Copy link
Author

@carolineschnapp
Copy link
Author

@carolineschnapp
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment