head tag missing in theme.liquid

Solved
Highlighted
Excursionist
59 0 1

Hello there,

 

I am helping a store owner. I want to add some code, including meta tags to the <head> section of the store. I'm using Themes API and updating theme.liquid. But theme.liquid for this store doesn't contain <head> . So how can I add the code? 

 

Note: I don't want to manually go and update in store owner's theme. And similarly I've updated the <head> tag of other stores. Only for this particular store I got this issue. 

 

Any help would be appreciated!

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 165

theme.liquid should contain the head (unless it's been removed intentionally) - do you have the store / theme details handy?

0 Likes
Highlighted
Excursionist
59 0 1

Hello @SBD_,

 

Now I can see the meta tag which we added to the theme got updated in theme.liquid. <meta name="xxxyyy" content="xxxxxyyy" />

Array
(
    [asset] => Array
        (
            [key] => layout/theme.liquid
            [public_url] => 
            [value] => <!doctype html>

<html class="no-js" lang="{{ request.locale.iso_code }}">
  <head><meta name="xxxyyy" content="xxxxxyyy" />
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, height=device-height, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="theme-color" content="{{ settings.accent_color }}">

    {%- capture seo_page_title -%}
      {%- if template contains 'search' and search.terms != blank -%}
        {{ search.terms | replace: '*', '' | split: ' AND ' | last }} - {{ shop.name }}
      {%- else -%}
        {{ page_title }}{% if current_tags %}{% assign meta_tags = current_tags | join: ', ' %} – {{ 'general.meta.tags' | t: tags: meta_tags }}{% endif %}{% if current_page != 1 %} – {{ 'general.meta.page' | t: page: current_page }}{% endif %}{% unless page_title contains shop.name %} – {{ shop.name }}{% endunless %}
      {%- endif -%}
    {%- endcapture -%}

    <title>{{- seo_page_title -}}</title>

    {%- if page_description -%}
      <meta name="description" content="{{ page_description | escape }}">
    {%- endif -%}

    <link rel="canonical" href="{{ canonical_url }}">

    {%- if settings.favicon -%}
      <link rel="shortcut icon" href="{{ settings.favicon | img_url: '96x' }}" type="image/png">
    {%- endif -%}

    <link rel="preload" as="style" href="{{ 'theme.scss.css' | asset_url }}">

    {% render 'social-meta-tags' %}

    {%- comment -%}Few prefech to increase performance on commonly used third-parties{%- endcomment -%}
    <link rel="preconnect" href="//fonts.shopifycdn.com">
    <link rel="dns-prefetch" href="//productreviews.shopifycdn.com">
    <link rel="dns-prefetch" href="//maps.googleapis.com">
    <link rel="dns-prefetch" href="//maps.gstatic.com">
.......................................................................................
            [created_at] => 2020-05-08T23:42:26-07:00
            [updated_at] => 2020-05-15T23:08:07-07:00
            [content_type] => text/x-liquid
            [size] => 6720
            [theme_id] => 80246112279
        )

)

But when I take the view-source of the store, I couldn't find the meta tag in the <head>. 
Note: This store is currently password protected. 

 

<!doctype html>

<html class="no-js" lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, height=device-height, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="theme-color" content="#144993">

    <title>SiteName</title><link rel="canonical" href="https://www.sitename.com/password"><link rel="shortcut icon" href="//cdn.shopify.com/s/files/xxxxxxx.png" type="image/png"><link rel="preload" as="style" href="//cdn.shopify.com/s/files/xxxxx/t/2/assets/theme.scss.css?v=zzzzzzzzzzz">

    <meta property="og:type" content="website">
...........................................................................................

 

I need one more help. If a store is not using Shopify theme, how can we add some code to the <head> tag. Will  theme.liquid  contain <head> for a custom theme ?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 165

This is an accepted solution.

Password protected stores render password.liquid, which doesn't use the theme.liquid layout. Once the store is live (password removed), your meta tag should be visible.

 

I need one more help. If a store is not using Shopify theme, how can we add some code to the <head> tag. Will  theme.liquid  contain <head> for a custom theme ?

It should, but no guarantees - someone might remove it. Your code should be prepared for this unlikely scenario.

1 Like
Highlighted
Excursionist
59 0 1

@SBD_ 

Thank you for the clarification. 

 

0 Likes