What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: Remove the tag parameter in collection urls

Remove the tag parameter in collection urls

LucasMondon
Excursionist
26 0 7

Hello all,

 

I would like to remove the crawl and indexing of my tagged collections because it creates duplicate content between "clean" collections without tags and tagged collections with parameters. In fact, the filter change nothing, it just rearranges the collection according to the product tags.

 

Despite the sitemap sent to google, the canonical tags to the right URLs, Google is indexing certain collections with a tag parameter (when you click on a tag to filter the collection). That's how Shopify works, I can't change it, the canonical URL of a tagged collection (for example  site/collections/collection-name/tag1) is 

site/collections/collection-name/tag1 

and not 

site/collections/collection-name

as I would like.

 

 

The tag parameter looks like this, it's

?constraint=tag1 

 

First solution I found :

I was thinking to add a remove filter to my canonical tag in my theme.liquid

this

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

to this

<link rel="canonical" href="{{ canonical_url | remove:"?constraint=" }}">

 

Second solution i found :

There is also Google URLs parameters

https://www.google.com/webmasters/tools/crawl-url-parameters

I think it would work, no ? I just have to put the ?constraint=  and Googlebot will not crawl and index the URLs with ?constraint= in it 

 

Third solution I found :

there is also this old thing 

{% if template contains 'collection' and current_tags %} <meta name="robots" content="noindex" />

 

thank you for your help, i really need it 

 

Replies 13 (13)

LitExtension
Shopify Partner
4877 1003 1169

Hi @LucasMondon,

You want this:

site/collections/collection-name/tag1

=>

site/collections/collection-name?constraint=tag1

Please add the following code:

{% assign url = link.url %}
                {% if link.title == 'collection-name' %}
                  {% assign tag = link.url | remove: link.object.url | remove: '/' %}
                  {% assign url = link.object.url | append: '?constraint=' | append: tag %}
                {% endif %}

Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
LucasMondon
Excursionist
26 0 7

Hello, 

 

thank you for your answer, but this is not what I was asking for.

i want to remove the tag parameter in my URLs, not adding one.

LitExtension
Shopify Partner
4877 1003 1169

Hi @LucasMondon,

Please send me the store link and screenshot where it needs to be changed.

I will check it.

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify

LucasMondon
Excursionist
26 0 7

i need help please, up

Emitoo
Visitor
1 0 1

Hey, I know it's a bit late, but I just wanted to share ma solution for the canonical problem with tags and parameters for anybody finding this on google.

 

First you would want to remove all the parameters from the canonical url like paginations etc. Then you would want to also remove all tags from the url. 

1. For the parameters: They are always separated from the actual url by exactly one "?". You can seperate these part by splitting the url at the "?" and taking the first part like so. You also still have access to the parameters via {{ url_params }}.

{%- assign new_canonical_url = canonical_url -%}
{%- if new_canonical_url contains '?' -%}
    {%- assign url_params = new_canonical_url | split: '?' | last -%}
    {%- assign new_canonical_url = new_canonical_url | split: '?' | first -%}
{%- endif -%}

 

2. For the tags: We can assume, that the tags behind the collection in the url will only happen on collection pages. So we can check if it is a collection page and if there are tags active. If so, the collection object has a url attached to it, which you can use to create the correct canonical url without any tags.

{% if template contains 'collection' and current_tags %}
    {%- assign new_canonical_url = collection.url | prepend: 'https://my-store.com' -%}
{% endif %}

This {{ new_canonical_url }} will then be cleaned from any parameters or tags and can be used instead of the default {{ canonical_url }}. Hope that helps

adityarao310
Tourist
4 0 2

Thank you! 

 

Adding the if clause below solves the problem! This way all /collection/tags pages get deindex which is fine! They are anyways eating up potential index space that Google is allowing my Shopify site. 

 

 

{% if template contains 'collection' and current_tags %} <meta name="robots" content="noindex" />

 

 

I added it in my head-tag.liquid and it worked like a charm. 

Offdaze
Excursionist
16 0 10

Hey @adityarao310 

 

Is this the only bit of code I need to add into my theme.liquid file to get this result or do I need to add anything else the thread author said? Did you add it to the top?

 

Thanks 🙂

adityarao310
Tourist
4 0 2

Only that code is fine. This way all /collections/tags pages will get deindexed too which is fine in this context 

Yes add it to the top in the Head section of the file .. it might be called `head-tag.liquid` in your theme files. 

You can see the code on my website 

Offdaze
Excursionist
16 0 10

Thanks so much for replying so quick! Yep that's exactly what I am looking to do, get rid of those annoying "Tagged" indexed urls.

 

So I don't have a head-tag.liquid in my theme files. I do have the theme.liquid. Maybe I could add it in here above/below the canonical bits?

 

Screenshot 2023-10-12 at 12.04.37 copy.jpg

 

Thanks for your help 🙂

adityarao310
Tourist
4 0 2

On first glance from your screenshot, yes, that should work. Do it once, and then visit a page on live website, if you see the right code in final HTML then its done 🙂

This code should basically add content="noindex" in the meta value called robots

Offdaze
Excursionist
16 0 10

That's great thanks so much! 🙂

Offdaze
Excursionist
16 0 10

Don't suppose if you'd be able to tell me if it's been implemented correctly?

 

view-source:https://www.jamesnewmanjewellery.co.uk/

view-source:https://www.jamesnewmanjewellery.co.uk/collections/sapphires

 

REVIEW.png

Offdaze
Excursionist
16 0 10

Just checked, all working! Woohoo! 🙂