Skip to content

Instantly share code, notes, and snippets.

@tinotriste
Last active December 20, 2018 19:16
Show Gist options
  • Save tinotriste/5328087 to your computer and use it in GitHub Desktop.
Save tinotriste/5328087 to your computer and use it in GitHub Desktop.
Shopify: Theme liquid tags for Facebook Open Graph
<!-- Find Current URL for og:url tag
https://github.com/joshuacc/Shopify-Snippets/blob/master/find-current-url.liquid -->
{% assign current_url = '' %}
{% case template %}
{% when 'page' %}
{% assign current_url = page.url %}
{% when 'blog' %}
{% assign current_url = blog.url %}
{% when 'article' %}
{% assign current_url = blog.url %}
{% when 'collection' %}
{% assign current_url = collection.url %}
{% when 'product' %}
{% assign current_url = product.url %}
{% endcase %}
<!-- End Find Current URL -->
<!-- Facebook Open Graph -->
{% if template contains 'product' %}
<meta name="og:image" content="{% for image in product.images %}{{ image.src | product_img_url: 'grande' }}{% endfor %}" />
{% else %}
<meta name="og:image" content="{{ 'logo.png' | asset_url }}" />
{% endif %}
<meta property="og:url" content="{{ shop.url }}{{ current_url }}" />
<meta property="og:title" content="{{ shop.name }}: {{ page_title }}" />
{% if template contains 'product' %}
<meta name="og:description" content="{{ product.description | strip_html | strip_newlines | escape }}" />
{% elsif template contains 'collection' %}
<meta name="og:description" content="{{ collection.description | strip_html | strip_newlines | escape }}" />
{% elsif template contains 'page' %}
<meta name="og:description" content="{{ page.content | strip_html | strip_newlines | escape }}" />
{% elsif template == 'index' %}
<meta name="og:description" content="{{ shop.description | strip_html | strip_newlines | escape}}" />
{% endif %}
{% if template contains 'product' %}
<meta name="og:type" content="product" />
{% else %}
<meta name="og:type" content="website" />
{% endif %}
<!-- End Facebook Open Graph -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment