├── .github
└── FUNDING.yml
├── LICENSE
├── README.md
├── json-ld-organization.liquid
├── json-ld-product.liquid
├── json-ld-search.liquid
├── metadata-og.liquid
├── metadata-twitter.liquid
├── random-number.liquid
└── random-product.liquid
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: pgrimaud
4 | custom: https://www.paypal.me/grimaudpierre
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Pierre Grimaud
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |

2 |
3 | # About Shopify Snippets
4 |
5 | Useful .liquid snippets for Shopify themes
6 |
7 | ## Why this repository?
8 |
9 | I developed several Shopify websites from scratch, without all-made themes.
10 |
11 | Last websites I worked on :
12 |
13 | - [https://paulandjoe.com/](https://paulandjoe.com/) for [Tribord Digital](https://triborddigital.com/)
14 | - [https://anashaf.com/](https://anashaf.com/) for [Tribord Digital](https://triborddigital.com/)
15 | - [https://hubside.store/](https://hubside.store/) for [Big Youth](https://www.bigyouth.fr/)
16 | - [https://www.statement.paris/](https://www.statement.paris/) for [Big Youth](https://www.bigyouth.fr/)
17 | - [https://www.caravane.fr/](https://www.caravane.fr/) for [Big Youth](https://www.bigyouth.fr/)
18 |
19 | As a back-end developer, I needed to created "ready to use" parts of code which can be reusable. That's the content of this repository.
20 |
21 | ## Snippets
22 |
23 | | File | Description |
24 | | ------------- | ------------- |
25 | | **[metadata-og.liquid](https://github.com/pgrimaud/shopify-snippets/blob/main/metadata-og.liquid)** | Generate MetaData OG for your template |
26 | | **[metadata-twitter.liquid](https://github.com/pgrimaud/shopify-snippets/blob/main/metadata-twitter.liquid)** | Generate MetaData Twitter for your template |
27 | | **[random-number.liquid](https://github.com/pgrimaud/shopify-snippets/blob/main/random-number.liquid)** | Get a random number |
28 | | **[random-product.liquid](https://github.com/pgrimaud/shopify-snippets/blob/main/random-product.liquid)** | Get a random product from shop or specific collection |
29 | | **[json-ld-search.liquid](https://github.com/pgrimaud/shopify-snippets/blob/main/json-ld-search.liquid)** | Generate JSON-LD [sitelinks search box](https://developers.google.com/search/docs/data-types/sitelinks-searchbox) |
30 | | **[json-ld-organization.liquid](https://github.com/pgrimaud/shopify-snippets/blob/main/json-ld-organization.liquid)** | Generate JSON-LD [organization](https://schema.org/Organization) |
31 | | **[json-ld-product.liquid](https://github.com/pgrimaud/shopify-snippets/blob/main/json-ld-product.liquid)** | Generate JSON-LD [product](https://developers.google.com/search/docs/data-types/product) |
32 |
33 | # Feedback
34 |
35 | You found a bug? You need a new feature? You can [create an issue](https://github.com/pgrimaud/shopify-snippets/issues) if needed or contact me on [Twitter](https://twitter.com/pgrimaud_).
36 |
37 | # Copyright
38 |
39 | This project is not affiliated with or endorsed by Shopify.
40 |
41 | [FeedArmy](https://feedarmy.com/) for JSON-LD product.
42 |
43 | Logo created with [Shopify Hatchful](https://hatchful.shopify.com/).
44 |
45 | # License
46 |
47 | Licensed under the terms of the MIT License.
48 |
--------------------------------------------------------------------------------
/json-ld-organization.liquid:
--------------------------------------------------------------------------------
1 | {%- comment -%}
2 | You have to change the logo asset on line 11.
3 | Also change social links started at line 13, with as many links you need.
4 | {%- endcomment -%}
5 |
6 |
22 |
--------------------------------------------------------------------------------
/json-ld-product.liquid:
--------------------------------------------------------------------------------
1 | {%- comment -%}
2 | Based from https://feedarmy.com/kb/shopify-microdata-for-google-shopping/
3 | Basic usage : {% render 'json-ld-product' %} in product template
4 | {%- endcomment -%}
5 |
6 |
7 | {%- assign fa_current_variant = product.selected_or_first_available_variant -%}
8 | {%- assign fa_variant_count = product.variants | size -%}
9 | {%- assign fa_count = 0 -%}
10 |
132 |
133 |
--------------------------------------------------------------------------------
/json-ld-search.liquid:
--------------------------------------------------------------------------------
1 | {%- comment -%}
2 | Nothing to do, just : {% render 'json-ld-search' %}
3 | {%- endcomment -%}
4 |
5 |
17 |
--------------------------------------------------------------------------------
/metadata-og.liquid:
--------------------------------------------------------------------------------
1 | {%- comment -%}
2 | You have to change the logo asset on line 32 & 33.
3 | {%- endcomment -%}
4 |
5 | {%- if template contains 'product' -%}
6 |
7 |
8 |
9 | {%- for image in product.images limit:3 -%}
10 |
11 |
12 | {%- endfor -%}
13 |
14 |
15 |
16 |
17 | {%- elsif template contains 'article' -%}
18 |
19 |
20 | {%- assign img_tag = '<' | append: 'img' -%}
21 | {%- if article.content contains img_tag -%}
22 | {%- assign src = article.content | split: 'src="' -%}
23 | {%- assign src = src[1] | split: '"' | first | remove: 'https:' | remove: 'http:' -%}
24 | {%- if src -%}
25 |
26 |
27 | {%- endif -%}
28 | {%- endif -%}
29 | {%- else -%}
30 |
31 |
32 |
33 |
34 | {%- endif -%}
35 | {%- if page_description and template != 'product' -%}
36 |
37 | {%- endif -%}
38 |
39 |
40 |
--------------------------------------------------------------------------------
/metadata-twitter.liquid:
--------------------------------------------------------------------------------
1 | {%- comment -%}
2 | You have to change the Twitter handle line 6.
3 | You have to change the logo asset on line 35. It must be a square picture.
4 | {%- endcomment -%}
5 |
6 |
7 |
8 | {% if template contains 'product' %}
9 |
10 |
11 |
12 |
13 |
14 |
15 | {% if product.vendor == blank %}
16 |
17 |
18 | {% else %}
19 |
20 |
21 | {% endif %}
22 | {% elsif template contains 'article' %}
23 |
24 |
25 |
26 | {% assign img_tag = '<' | append: 'img' %}
27 | {% if article.content contains img_tag %}
28 | {% assign src = article.content | split: 'src="' %}
29 | {% assign src = src[1] | split: '"' | first | remove: 'https:' | remove: 'http:' %}
30 | {% if src %}
31 |
32 | {% endif %}
33 | {% endif %}
34 | {% else %}
35 |
36 | {% endif %}
37 |
--------------------------------------------------------------------------------
/random-number.liquid:
--------------------------------------------------------------------------------
1 | {%- comment -%}
2 | Wanna change the range, just edit line 10 & 11
3 |
4 | Basic usage :
5 | {% render 'random-test' %}
6 | {{ random_number }} -> here's your random number
7 | {%- endcomment -%}
8 |
9 | {%- assign min = 0 -%}
10 | {%- assign max = 9999999 -%}
11 | {%- assign diff = max | minus: min -%}
12 | {%- assign random_number = "now" | date: "%N" | modulo: diff | plus: min -%}
13 |
--------------------------------------------------------------------------------
/random-product.liquid:
--------------------------------------------------------------------------------
1 | {%- comment -%}
2 | Basic usage to get a random product from all your shop :
3 | {%- render 'random-product' -%}
4 | {{ random_product }} -> here's your random product
5 |
6 | Basic usage to get a random product from a specific collection :
7 | {%- render 'random-product' with specific_collection: 'sport' -%}
8 | {{ random_product }} -> here's your random product
9 | {%- endcomment -%}
10 |
11 | {%- if specific_collection -%}
12 | {%- assign all_products_from_collection = collections[specific_collection].products -%}
13 | {%- else -%}
14 | {%- assign all_products_from_collection = collections['all'].products -%}
15 | {%- endif -%}
16 |
17 | {%- assign all_products_random = '' -%}
18 |
19 | {%- for product_splitted in all_products_from_collection -%}
20 | {%- assign all_products_random = all_products_random | append: product_splitted.handle | append: ',' -%}
21 | {%- endfor -%}
22 |
23 | {%- assign all_products_random_splited = all_products_random | split: ',' -%}
24 |
25 | {%- assign min = 0 -%}
26 | {%- assign max = all_products_random_splited.size | minus: 1 -%}
27 | {%- assign diff = max | minus: min -%}
28 | {%- assign random_number = "now" | date: "%N" | modulo: diff | plus: min -%}
29 |
30 | {%- assign random_product_slug = all_products_random_splited[random_number] -%}
31 | {%- assign random_product = all_products[random_product_slug] -%}
32 |
--------------------------------------------------------------------------------