meta-tags Snippet
snippets/meta-tags.liquid outputs SEO and social meta tags (Open Graph, Twitter) and the <title> tag. It automatically adapts tags for product, article, and password pages. The component generates comprehensive meta tags for search engines and social media sharing, including structured data for products.
What It Does
- Outputs essential HTML meta tags (charset, viewport, X-UA-Compatible).
- Generates Open Graph meta tags for social sharing.
- Generates Twitter Card meta tags.
- Creates page title with shop name and pagination.
- Outputs canonical URL link.
- Generates meta description.
- Creates structured data (JSON-LD) for products.
- Adapts tags based on page type (product, article, password).
Parameters
None. This snippet takes no parameters. It reads from global Liquid objects.
Dependencies & Assets
| Type | Files / Components |
|---|---|
| CSS | None required |
| JavaScript | None required |
| Shopify Objects | page_title, canonical_url, page_description, page_image, shop, product, cart, request, current_tags, current_page |
| Shopify Filters | escape, image_url, money_without_currency, strip_html, join, structured_data |
- No external dependencies required.
- All data comes from Shopify Liquid objects.
- Shopify filters handle formatting and escaping.
Dynamic Styles
The snippet does not include any styles. It only outputs HTML meta tags and structured data.
Markup Structure
The snippet outputs HTML meta tags in the <head> section:
Essential Meta Tags
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">Open Graph Tags
<meta property="og:site_name" content="{{ shop.name }}">
<meta property="og:url" content="{{ og_url }}">
<meta property="og:title" content="{{ og_title | escape }}">
<meta property="og:type" content="{{ og_type }}">
<meta property="og:description" content="{{ og_description | escape }}">Open Graph Image Tags (Conditional)
{%- if page_image -%}
<meta property="og:image" content="http:{{ page_image | image_url }}">
<meta property="og:image:secure_url" content="https:{{ page_image | image_url }}">
<meta property="og:image:width" content="{{ page_image.width }}">
<meta property="og:image:height" content="{{ page_image.height }}">
{%- endif -%}Product-Specific Tags
{%- if request.page_type == 'product' -%}
<script type="application/ld+json">
{{ product | structured_data }}
</script>
<meta property="og:price:amount" content="{{ product.price | money_without_currency | strip_html }}">
<meta property="og:price:currency" content="{{ cart.currency.iso_code }}">
{%- endif -%}Twitter Card Tags
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="{{ og_title | escape }}">
<meta name="twitter:description" content="{{ og_description | escape }}">Title Tag
<title>
{{ page_title }}
{%- if current_tags %} – tagged "{{ current_tags | join: ', ' }}"{% endif -%}
{%- if current_page != 1 %} – Page {{ current_page }}{% endif -%}
{%- unless page_title contains shop.name %} – {{ shop.name }}{% endunless -%}
</title>Canonical Link
<link rel="canonical" href="{{ canonical_url }}">Meta Description (Conditional)
{% if page_description %}
<meta name="description" content="{{ page_description | escape }}">
{% endif %}Behavior
- Page type detection: Detects page type and adapts meta tags accordingly.
- Open Graph type: Sets
og:typeto 'product', 'article', or 'website' based on page. - URL handling: Uses canonical URL or request origin based on page type.
- Image handling: Includes Open Graph image tags when
page_imageis available. - Structured data: Outputs JSON-LD structured data for product pages.
- Price information: Includes product price in Open Graph tags for product pages.
- Title construction: Builds title with page title, tags, pagination, and shop name.
- Content escaping: All user-generated content is escaped for security.
Usage Example
{% render 'meta-tags' %}Typically used in:
- Theme layout (
layout/theme.liquid) in<head>section
Implementation Notes
No parameters: Snippet takes no parameters - reads all data from global Liquid objects.
Essential meta tags: Outputs three essential meta tags:
charset="utf-8": Character encodingX-UA-Compatible: IE compatibilityviewport: Responsive viewport settings
Open Graph variables: Calculates Open Graph values:
og_title:page_titleorshop.nameog_url:canonical_urlorrequest.originog_type: 'website', 'product', or 'article'og_description:page_descriptionorshop.descriptionorshop.name
Page type detection: Detects page type via
request.page_type:'product': Setsog_typeto 'product''article': Setsog_typeto 'article''password': Usesrequest.originfor URL- Otherwise: Uses 'website' type
Open Graph tags: Generates standard Open Graph meta tags:
og:site_name: Shop nameog:url: Page URLog:title: Page titleog:type: Content typeog:description: Page description
Open Graph image: Conditionally includes image tags when
page_imageis available:og:image: HTTP image URLog:image:secure_url: HTTPS image URLog:image:width: Image widthog:image:height: Image height
Product structured data: Outputs JSON-LD structured data for product pages using
product | structured_data.Product price tags: Includes Open Graph price tags for product pages:
og:price:amount: Product price (without currency symbol)og:price:currency: Currency ISO code
Twitter Card tags: Generates Twitter Card meta tags:
twitter:card: Set to 'summary_large_image'twitter:title: Page titletwitter:description: Page description
Title construction: Builds title with:
- Base:
page_title - Tags:
– tagged "tag1, tag2"(if tags exist) - Pagination:
– Page 2(if not page 1) - Shop name:
– Shop Name(if not already in title)
- Base:
Canonical URL: Outputs canonical link tag for SEO.
Meta description: Conditionally outputs meta description when
page_descriptionexists.Content escaping: All user-generated content escaped using
escapefilter:- Titles
- Descriptions
- Tags
Image URL generation: Uses
image_urlfilter to generate image URLs.Price formatting: Uses
money_without_currencyandstrip_htmlfilters for price.Tag joining: Uses
joinfilter to combine tags with comma separator.Structured data format: Product structured data output as JSON-LD script tag.
Currency code: Uses
cart.currency.iso_codefor currency information.Secure image URL: Generates both HTTP and HTTPS image URLs for compatibility.
Image dimensions: Includes image width and height for proper display.
Password page handling: Password pages use
request.origininstead of canonical URL.Title shop name check: Only adds shop name if not already in title.
Tag display: Tags displayed in quotes with comma separation.
Pagination display: Page number only shown if not page 1.
Description fallback: Description falls back to shop description or shop name.
URL fallback: URL falls back to request origin if canonical URL not available.
Title fallback: Title falls back to shop name if page title not available.
Type fallback: Open Graph type defaults to 'website'.
Image conditional: Image tags only output when
page_imageis available.Description conditional: Meta description only output when
page_descriptionexists.Product conditional: Product-specific tags only output on product pages.
Structured data script: Structured data wrapped in
<script type="application/ld+json">tag.Price strip HTML: Price stripped of HTML tags for clean numeric value.
Currency ISO code: Uses ISO currency code (e.g., 'USD', 'EUR').
Image protocol: Generates both HTTP and HTTPS image URLs.
Tag separator: Tags joined with comma and space:
', '.Title separator: Title parts separated with
–(en dash).Shop name check: Checks if shop name already in title to avoid duplication.
Page number format: Page number formatted as "Page 2" (not "Page 1").
Tag format: Tags formatted as
tagged "tag1, tag2".Canonical link: Uses
rel="canonical"for SEO.Meta description name: Uses
name="description"(notproperty).Open Graph property: Uses
propertyattribute (notname).Twitter name: Uses
nameattribute for Twitter tags.Structured data type: Uses
application/ld+jsonMIME type.Image URL filter: Uses
image_urlfilter without size parameter (uses original size).Price without currency: Strips currency symbol for numeric price value.
HTML stripping: Strips HTML from price for clean numeric value.
Content security: All user content escaped to prevent XSS.
SEO best practices: Follows SEO best practices for meta tags and structured data.