Last active
December 20, 2018 19:16
-
-
Save tinotriste/5328087 to your computer and use it in GitHub Desktop.
Shopify: Theme liquid tags for Facebook Open Graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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