Creating Meta Tags

by mhromney75 - Member - 06:52PM, Apr 30, 2008

Hi Everyone,

I have a couple questions about meta tags. (I don’t know much about HTML)
I have been searching these forums trying to find a way to add Meta tags to my site. And I have found two possibilities Listed below:

First

  {% case 'page_title' %}

{% when 'Welcome' %}
 <meta name="description" content="Description here"/>
 <meta name="keywords" content="Keywords here" />

{% when 'Product-Foo' %}
 <meta name="description" content="{{ product.description }}"/>
 <meta name="keywords" content="keywords here">

{% endcase %}

Posted by DanW (http://forums.shopify.com/categories/6/posts/8789#comment-8791)

I couldn’t get this one to work.

Second

  {% if collection %}
  {% if collection.handle == "testcollection" %}
    <meta name="description" content="This is my testcollection">
  {% endif %}
or
{% if collection %}
  <meta name="keywords" content="{% for tag in collection.tags %}{{ tag }} {% endfor %}">
{% endif %}
Posted by daniel (http://forums.shopify.com/categories/1/posts/14404#comment-14540)

I couldn’t get this one to work the way I wanted so I had to modify it a little bit in order to get it to work see below.

{% if page.title != 'Shopify T-Shirt' %}
 <meta name="description" content="Description here"/>
 <meta name="keywords" content= {{ product.tags | join: ', ' }} />
{% endif %}  

http://svmountain.myshopify.com/products/shopify-t-shirt

After doing this however I realized that if I did it this way I would have to create a snippet of code for all of my 300 products. So after looking at this code for a bit (remember I am a novice so this isn’t as apparent to me as it may be to the rest of you) I realized that the Meta Keywords portion is dynamic. So I thought I can just put that in my theme.liquid and it will pull whatever tags are on my product pages and turn them into keywords. So that is what I did. See below

 <meta name="keywords" content= {{ product.tags | join: ', ' }} />

http://www.survivalmountain.com/products/spot-satellite-messenger

So I added this but I have noticed that for any page on my site that is not a product page it has this snippet of code with no keywords. So I have a couple questions on this (example: http://www.survivalmountain.com/collections/food)

1.Does anyone know how to make this more dynamic? So if it is on a collection page it will display the tags for that page or if it is on the product page it will display the tags for that page. Maybe there is a universal tag command I can put in the content section and it will pick up whatever tags are associated with the page and turn them into keywords.

2. I have also noticed that other websites have both the Meta Keyword & Meta Description. Do I need both? Can I make the Meta Description Dynamic also?

mhromney75

Member

07:15PM, May 02, 2008

Is there anyone out there that can help me on this?

leeann

Member

05:46AM, May 07, 2008

I tried this code recently and it didn’t work. Does anyone have any advice on how I can install some meta tags on to my site that aren’t the same on each page? Any help would be appreciated.

Christina

Miss Manners

12:28PM, May 07, 2008

First of all: there’s a difference between two variables that look very similar but that are actually quite different:

1) page.title (with the period):

this refers only to the title of a page.liquid template, e.g., the one that might be called “About-us”. There is no “page.title” variable that refers to the product, the collection, or any other template than page, so your code above, that starts {% if page.title != 'Shopify T-Shirt' %} would never work.

2) page_title (with the underscore):

this is a variable that refers to each template differently, as follows:

  • collection: the name of the collection currently shown (= collection.title)
  • product: the name of the product currently shown (= product.title)
  • page: the title of the page (= page.title)
  • blog: the title of the blog (not the article) (= blog.title)
  • index: the word ‘Welcome’
  • cart: the words ‘Your Shopping Cart’
  • search: the word ‘Search’

You can test this by temporarily putting the variable:

<h1>{{page_title}}</h1>
in a visible place in your theme.template, and navigating around your site to see how it changes.

So if you put {{page_title}} in your meta description, it will automatically give you the product titles, collection title and so on.

Now some code:

{% assign maxwords = 20 %}
{% assign indexblog = 'frontpage' %}

{% case template %}
    {% when 'collection' %}
        <meta name="description" content="{{page_title}}{% if collection.description.size > 0 %}: {{collection.description | strip_html | truncatewords:maxwords}}{% endif %}"/>
        <meta name="keywords" content= "{{collection.title}}{% if collection.tags.size > 0 %}: {{ collection.tags | join: ', ' }}{% endif %}" />
    {% when 'product' %}
        <meta name="description" content="{{page_title}}{% if product.description.size > 0 %}: {{product.description | strip_html | truncatewords:maxwords}}{% endif %}"/>
        <meta name="keywords" content="{{product.title}}{% if product.tags.size > 0 %}: {{ product.tags | join: ', ' }}{% endif %}">
    {% when 'page' %}
        <meta name="description" content="{{page_title}}: {{page.content | strip_html | truncatewords:maxwords}}"/>
        <meta name="keywords" content="{{page_title}}">
    {% when 'blog' %}
        <meta name="description" content="{{page_title}}"/>
        <meta name="keywords" content="{{page_title}}">
    {% else %}
        <meta name="description" content="{{shop.name}}{% if blogs.[indexblog].articles.size > 0 %}: {% for article in blogs.[indexblog].articles limit:1 %}{{ article.title }}: {{article.content | strip_html | truncatewords:maxwords}}{% endfor %}{% endif %}"/>
        <meta name="keywords" content= "{% for link in linklists.Main-Menu.links %}{% if link.type == 'collection_link' %}{{link.title}} {% endif %}{% endfor %}" />
{% endcase %}    

Code explanation:

The above will give you the following results:

For the collection template:

Description: The title of the collection, followed by an excerpt of the collection description, if you’ve made one. Keywords: Collection title + tags for that collection.

For the product template:

Description: The product title, followed by an excerpt of the product description, if you have one. Keywords: Product title + tags for that product.

For the page template:

Description: The page title, followed by an excerpt of the page article. Keywords: Page title.

For the blog template:

Description: The blog title. Keywords: Blog title.
(this could be expanded somewhat, to include more specifics)

All other templates including index:

Description: The name of the shop, followed by an excerpt of the frontpage article. Keywords: A list of the shop collections that are in the Main Menu.

There are two variables you can change:

maxwords : to increase or decrease the number of words in the excerpts.

indexblog : which refers to a blog called ‘frontpage’. If your blog is called somwthing else, you can change that, without messing with the code.

Which you are otherwise free to mess with as you please, of course.

Though I actually think the <title> attribute is more important than the keywords. You can customize that in a very similar fashion.

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

mhromney75

Member

12:59AM, May 10, 2008

Christina Thanks!!

This works great.

Christina

Miss Manners

10:53AM, May 26, 2008

see also continuation of meta description discussion

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

JohnG

Member

11:09PM, Jun 05, 2008

I was finally able to do this – almost. Pretty slick! Meta Descriptions work fine throughout except Keywords for my Index page. Comments say, “All other templates including index: Description: The name of the shop, followed by an excerpt of the frontpage article. Keywords: A list of the shop collections that are in the Main Menu.”

It is this latter part that is not visible. I tried to puzzle out, but could not. What did I miss?

Christina

Miss Manners

04:35PM, Jun 06, 2008

Do you use the default menu provided by shopify? The one that’s called “Main Menu”? The above code assumes that; I shouldn’t have hard-coded that, but there you go.

If your collections are listed in a linklist that is called something else, then replace the handle “Main-Menu” in the last line above by the handle of your linklist, like this:

Instead of this:

<meta name="keywords" content= "{% for link in linklists.Main-Menu.links %}...

do this:

<meta name="keywords" content= "{% for link in linklists.your-linklist-name.links %}...

or maybe i should have set “main-menu” lowercase.

Anyway, try that & see. Tell me if it doesn’t work.

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

JohnG

Member

07:26PM, Jun 06, 2008

I think we are SOL. Our design uses hard coded links. See page source at: http://www.aplusenv.com/

So, I am wondering if your other Meta Tag code solution – http://forums.shopify.com/categories/6/posts/19827 – can be modified to handle Key Words?

I have played with the Meta Descriptions blog articles, etc. and it is perfect for my needs! I like it because it provides a lot more control over content.

Christina

Miss Manners

11:32AM, Jun 07, 2008

hmm. what does SOL mean?

Looking at page source will not tell me whether something’s hard-coded or not, & I very much doubt it would be. That would be just too SOL for words.

In your admin → navigation, check what linklists you have, and then see which links connect to the collections. Put in the name of that linklist.

I’m glad you’re liking the metadescriptions blog solution. You could do that for keywords, too, make a new blog called, um, let’s see…”keywords” and change the code correspondingly, mutatis mutandis et cetera.

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

JohnG

Member

09:02PM, Jun 07, 2008

My admin → navigation shows no linklists, just:

Main Menu → Home

Footer → Home, Resources, Events, Classes, Contact Us, Privacy

None of which I want to use as Keywords

I am going to try to modify your metadescriptions blog solution for “keywords,” and since I have no idea what I am doing it should be …. um …. an adventure?

2.5 hours Later …

It was an adventure and it works! Thanks a bunch Christina!

Christina

Miss Manners

03:04AM, Jun 08, 2008

congrats!! i love it when that happens.

weird nav setup you got there though. you’re clearly not using your Main Menu linklist. if you just add links there for each of your collections, the above code should work, and give you the collection names as keywords for your index page.

But I guess you’ve gone with the blog. While you’re at it, impossibly refining your head section, you might as well stick the title tags in there too.

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

Chelsea

Member

08:40PM, Jun 09, 2008

I am going to try to use this to display user feedback on product pages.

You rock Christina.

---

Chelsea

My Shopify Site:
::::::::::::::::
http://www.SleepySheep.ca
http://www.SleepySheepBedding.com

Other Shopify Integrations:
:::::::::::::::::::::
http://www.ecocessories.ca

Christina

Miss Manners

02:55AM, Jun 10, 2008

ooo. why thank you. glad you like it.
plus i sleep on a 100% wool bed, made specially by my local wool bed maker :)
very nice site you have.

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

Chelsea

Member

03:53AM, Jun 10, 2008

I sleep on a wool bed too; along with my wool bedding, it’s the best sleep I have ever had.

I will post to this thread when I have figured out the user feedback using the code above.

Wool rules.

---

Chelsea

My Shopify Site:
::::::::::::::::
http://www.SleepySheep.ca
http://www.SleepySheepBedding.com

Other Shopify Integrations:
:::::::::::::::::::::
http://www.ecocessories.ca

FannyA

Member

10:57AM, Jun 11, 2008

Christina, thanks for the code, I’ll try it.

Chelsea, I’m looking forward to your code for user feedback.

Lastly, my little lamb is sleeping on a sheepskin since birth and still loving it 2 years later.

Chelsea

Member

03:00PM, Jun 11, 2008

I will keep working on the user feedback stuff tonight; slow going, as my grasp on liquid is tenuous, but I think I have it half working at least.

Here is what I intend to be able to do with it when done:

- Define the content for unspecified pages in a Feedback blog that would display on a site
- Display Feedback for specific products, either that are already in the cart, or that are being viewed by the potential customer.

Aside: That’s wonderful FannyA; my daughter Raechel is 9, and she sleeps on a wool and natural latex bed, as well as under a wool duvet. (So do I for that matter.) It has improved my allergies and asthma considerably, to the point that I no longer needing an inhaler.

---

Chelsea

My Shopify Site:
::::::::::::::::
http://www.SleepySheep.ca
http://www.SleepySheepBedding.com

Other Shopify Integrations:
:::::::::::::::::::::
http://www.ecocessories.ca

leeann

Member

11:58PM, Jun 14, 2008

Hi, I’m back again… I installed the code above that Christina supplied, the description is working somewhat, but it doesn’t put a comma between my meta keywords, I would also like to be able to specify the keywords I would like to use on each page without having to use the links list.

Does anyone how I can get around using the link list as my keywords?

Thanks in advanced!

Lee Ann

FannyA

Member

06:25PM, Jun 15, 2008

Christina, shall I just copy and paste your code into theme.liquid?
Sorry I’m rubbish at technique.

Edited to add
It works! I pasted the code in the head of my theme.liquid. I did View page source on my website and it worked.
Thanks a bunch!

FannyA

Member

12:28PM, Jun 16, 2008

Hi Folks,

I have errors with IE. HTML validator says that <meta> are not closed.

I added </meta> at the end of each code line Christina gave us and now he says “discarding unexpected </meta>”.

What to do? Please could somebody help me?

FannyA

Member

12:39PM, Jun 16, 2008

I think I fixed it…. sorry it’s so blurry for me ;-)

Christina

Miss Manners

04:08AM, Jun 17, 2008

Fanny, you found a bug in my code – sorry about the trouble it’s caused you.

The problem arises because I was sloppy about closing the self-closing meta tags. The proper way to do it, if you’re using an xhtml doctype (which you are) is: space – backslash – closing bracket. In some of the lines above, I didn’t put in the space, and in others, I’m even missing the backslash, egad!

The right way:

<meta name="whatever" content="whatever" />

corrected code:

{% assign maxwords = 20 %}
{% assign indexblog = 'frontpage' %}

{% case template %}
    {% when 'collection' %}
        <meta name="description" content="{{page_title}}{% if collection.description.size > 0 %}: {{collection.description | strip_html | truncatewords:maxwords}}{% endif %}" />
        <meta name="keywords" content= "{{collection.title}}{% if collection.tags.size > 0 %}: {{ collection.tags | join: ', ' }}{% endif %}" />
    {% when 'product' %}
        <meta name="description" content="{{page_title}}{% if product.description.size > 0 %}: {{product.description | strip_html | truncatewords:maxwords}}{% endif %}" />
        <meta name="keywords" content="{{product.title}}{% if product.tags.size > 0 %}: {{ product.tags | join: ', ' }}{% endif %}" />
    {% when 'page' %}
        <meta name="description" content="{{page_title}}: {{page.content | strip_html | truncatewords:maxwords}}" />
        <meta name="keywords" content="{{page_title}}" />
    {% when 'blog' %}
        <meta name="description" content="{{page_title}}" />
        <meta name="keywords" content="{{page_title}}" />
    {% else %}
        <meta name="description" content="{{shop.name}}{% if blogs.[indexblog].articles.size > 0 %}: {% for article in blogs.[indexblog].articles limit:1 %}{{ article.title }}: {{article.content | strip_html | truncatewords:maxwords}}{% endfor %}{% endif %}" />
        <meta name="keywords" content= "{% for link in linklists.Main-Menu.links %}{% if link.type == 'collection_link' %}{{link.title}} {% endif %}{% endfor %}" />
{% endcase %}

You have to get rid of the </meta> in your html, that’s not the right syntax.
Hope this helps.

@leeann: if you want more customization of keywords, use the other meta tag method given here, and adapt it to work for keywords too, like JohnG did (see comments above).

@JohnG: wanna share your adventurous code?

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

JohnG

Member

01:33AM, Jun 21, 2008

Christina, I’d be happy to share but it would duplicate what is already available. I used your code “right out of the box” – that is I cut and pasted it from your post to my theme.liquid between the <head></head> tags. I then created the metadescription blogs as explained in your post and it worked!

Once I had the Descriptions part functioning, I took the same code and search/replaced the word “description” with “keywords” and put this directly under the metadescription code. Then I added metakeyword blogs and that’s it.

Two things I’d like to improve/fix are (1) stripping out the page titles that display before each meta description and (2) eliminate the extra areas of white space before and after the meta tags.

I’ve tried to figure out how to do both, but am stumped.

Any suggestions?

Christina

Miss Manners

12:52PM, Jun 21, 2008

ok.

you can get rid of the page titles by removing all instances of page_title from the code – maybe just leaving it in for the blog template, otherwise you won’t have much meta to show.

the whitespace cannot be removed by us. it’s the trace left behind from processing all the conditional statements. the shopify crew would have to do something to their code to fix that, but i’m not sure that that is (or should be) a huge priority. it’s not very pretty, but it’s harmless.

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

JohnG

Member

07:02PM, Jun 21, 2008

Thanks Christina.

For some reason, I am unable to strip the page title out of the meta keyword displays on my ‘collection’ pages. The code snippet in question is:

<meta name="keyword" content=" 
{% capture meta_default %}
    {% case template %}
        {% when 'collection' %}
            {{page_title}}{% if collection.keyword.size > 0 %} {{collection.keyword | strip_html | truncatewords:maxwords}}{% endif %}
        {% when 'product' %}
            {{page_title}}{% if product.keyword.size > 0 %}: {{product.keyword | strip_html | truncatewords:maxwords}}{% endif %}
        {% when 'blog' %}
            {% if blog.articles.size == 1 %}
                {% for article in blog.articles %}
                    {{article.content | strip_html | truncatewords:maxwords}}
                {% endfor %}
            {% else %}
                {{page_title}}
            {% endif %}
        {% else %}
             {{shop.name}}: {% if blogs[indexblog].articles.size > 0 %}: {% for article in blogs[indexblog].articles limit:1 %}{{ article.title }}: {{article.content | strip_html | truncatewords:maxwords}}{% endfor %}{% endif %}
    {% endcase %} 
{% endcapture %}

I deleted {{page_title}} from the “collection’ portion, but it still displays prior to the metakeywords. Is it being fed from the blog which, of course, has the same title? FYI, I want to retain the titles for all other pages, just not on the ‘collection’ pages.

What am I missing?

Guy15

Member

04:45AM, Jul 14, 2008

Christina, and everyone. I hate to sound dumb but I have been reading these meta tag forums for hours and it doesnt all make complete sense to me yet.

Where do I put this code in assets, and what variables do i change, with my own data? I simply need to incorporate meta descriptions and am at square 1. Though my site generates sales daily, I am a beginner with coding. Be gentle.

www.breastformshop.com

Christina

Miss Manners

07:29AM, Jul 14, 2008

code doesn’t go into assets; it goes into templates.
this one goes into the template called “theme”.
go to admin ->assets ->theme editor.
click on “theme”. copy and paste the code that you see there to a safe place, (such as notepad, if you’re on windows.) make a backup. make another backup. then you can start messing around with it. copy and paste the code from here to your theme template, after the first line of meta tag you see. that’s basically it.

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

Guy15

Member

01:45PM, Jul 14, 2008

so then I just replace the words “keywords” and “description” with my own? Do keywords need to be separated with comma or just space? thanks

Guy15

Member

05:42PM, Jul 14, 2008

Also do I have to change ‘page_title’ or anything to meet my handles?

Guy15

Member

04:11AM, Jul 18, 2008

bump

Caroline Schnapp

Member

03:42PM, Jul 18, 2008

so then I just replace the words “keywords” and “description” with my own?

No.

Christina said: “copy and paste the code from here to your theme”.

Also do I have to change ‘page_title’ or anything to meet my handles?

No again.

Christina said: “copy and paste the code from here to your theme”.

Sorry to barge in.

Guy15

Member

04:45PM, Jul 18, 2008

I thought thats what she meant but how am I supposed to determine what keywords to use? I would like to pick keywords most relevant. Thanks

Guy15

Member

05:31PM, Jul 25, 2008

Ok I am learning some of the lingo and I figured out most of this. The only thing I want to figure out is how I can enter some code that I can determine my own keywords, rather than let it pull the title (which isn’t showing up anyway). So do I make another page called keywords then fill it in or what? I almost have this, thanks.

www.ozonhair.com
www.breastformshop.com

Internet Marketing

Member

06:14AM, Sep 10, 2008

Need help…..I can’t get unique meta tags to work on each of my pages. I am using the following code.

Based on this post http://www.bestrank.com/blog/making-your-shopify-site-seo-friendly-141/#comment-1243 it should work.

Any help? please…..thank you.

{% case page_title %}
{% when null %}
<title>{{shop.name}} – {{page_title}}</title>
{% when ‘Welcome’ %}
<title>T-Shirt Printer | T-Shirt Customization</title>
<meta name="”keywords”" content="”t-shirt" printing>
<meta t-shirt name="”description”" and own customize content="”Create" your>
{% else %}
<title>{{shop.name}} | {{page_title}}</title>
{% assign maxwords = 20 %}
{% assign indexblog = ‘frontpage’ %}

{% case template %}
{% when ‘collection’ %}
<meta name="”description”" collection if content="”{{page_title}}{%"> 0 %}: {{collection.description | strip_html | truncatewords:maxwords}}{% endif %}”/>
<meta name="”keywords”" collection if content="“{{collection.title}}{%"> 0 %}: {{ collection.tags | join: ‘, ‘ }}{% endif %}” />
{% when ‘product’ %}
<meta name="”description”" product if content="”{{page_title}}{%"> 0 %}: {{product.description | strip_html | truncatewords:maxwords}}{% endif %}”/>
<meta name="”keywords”" product if content="”{{product.title}}{%"> 0 %}: {{ product.tags | join: ‘, ‘ }}{% endif %}”>
{% when ‘page’ %}
<meta name="”description”" content="”{{page_title}}:">
<meta name="”keywords”" content="”{{page_title}}”">
{% when ‘blog’ %}
<meta name="”description”" content="”{{page_title}}”" />
<meta name="”keywords”" content="”{{page_title}}”">
{% else %}
<meta name="”description”" if content="”{{shop.name}}{%" blogs> 0 %}: {% for article in blogs.[indexblog].articles limit:1 %}{{ article.title }}: {{article.content | strip_html | truncatewords:maxwords}}{% endfor %}{% endif %}”/>
<meta name="”keywords”" linklists in content="“{%" link for>
{% endcase %}
{% endcase %}

Christina

Miss Manners

05:38PM, Sep 18, 2008

whose site is that you link to?

that page says we came up with a relatively simple way to include custom tags on your Shopify site”

more like ”we grabbed this code from right here (see above), mangled it because we don’t understand it, and then posted it on our site as ours.

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

Caroline Schnapp

Member

07:41PM, Sep 18, 2008

Usually, those who claim they are SEO specialists know shit about HTML. (And if I dare say, have very relaxed ethics in general…)

It is imperative that these folks know about HTML because search engines read HTML.

That is ludicrous (from ‘the’ site):

You want to place the code between the head tag and body tag on the theme.liquid page.

More like between the opening and closing tags of the head element.

In his response to Christina he states that:

Also, all of the conditionals that we worked with were placed on the “theme.liquid” page as opposed to altering each individual template page.

Christina never said you have to alter template pages. Why would she use a conditional on the type of template if she did not place her code in theme.liquid?

The blind leading the blind.

People who want to ride the wave of ecommerce, but who are not computer-savvy, become SEO specialists, quite often. They remind me of chiropracters (although like chiropracters there are probably a few good ones out there): “Give me a couple of thousands dollars (or hundreds) and you will feel less pain. Of course, it’s not for tomorrow, it will take 3-4 months, maybe more time…” Etc.

Caroline Schnapp

Member

07:45PM, Sep 18, 2008

Repeat. Bad Internet connection.

Caroline Schnapp

Member

02:06PM, Jun 24, 2009

John Stevesone is a spammer. Please ban these people…

tobi

Shopify

02:08PM, Jun 24, 2009

he is gone ;-)

The suggestions in this thread are good. We also have a little feature on our roadmap that will allow people to enter per page meta tag overrides and page title overrides.

This should be part of a deployment this summer.

---

Tobias Lütke
Shopify CEO

thepims

Member

01:39PM, Jun 25, 2009

@Tobi please please please! That would be great!

host waffle

Member

10:35AM, Jun 29, 2009

Does anyone know how to make this more dynamic? So if it is on a collection page it will display the tags for that page or if it is on the product page it will display the tags for that page. Maybe there is a universal tag command I can put in the content section and it will pick up whatever tags are associated with the page and turn them into keywords.

Thanks.

fom

http://www.hostwaffle.com

You must login to post a comment!

Don't have an account yet? Sign up for one.