{% if product.url contains 'col=' %} on product page to display certain link

What we are trying to do on a product level is that if a URL contains ?col=father at the end that it displays a link on the product page like Everything the the collection ‘Father’

Now i can accomplish this with the following:

{% if product.url contains 'fater' %} <a href="domain.com/collections/father">Everything the the collection 'Father'</a>
{% endif %}

But there is a problem. We want to do this for a ton of collection so it is humanly impossible to create a ton of if statements.

So i am looking for a solution that it fetches whatever is after ?col=
And in return display that in the HREF.

We can then use links in our advertisment including ?col= to make sure it always displays the correct collection URLs

Hope this makes sense and i hope someone knows the answer :slightly_smiling_face:

Hi ,

They may be useful to you, you can check the following, I gave a few examples.

{%- capture querystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign pageURL = querystring | split:‘“pageurl”:"’ | last | split:‘"’ | first | split:‘.myshopify.com’ | last | replace:‘/’,‘/’ | replace:‘%20’,’ ’ | replace:‘\u0026’,‘&’ -%}

{% if pageURL contains ‘fater’ %} Everything the the collection ‘Father’
{% endif %}

{% if pageURL contains “col” %}
console.log(‘link: {{pageURL}}’);
{% endif %}