Custom Canonical URL

ShopifyHelp1
New Member
3 0 0

I have this page

https://blissfulsleep.com/pages/mattress-store-los-angeles-ca

I would like the canonical URL to point to the homepage. The homepage pulls this page's content as its own.

Is there a way I can set a custom canonical URL for this page?

Replies 8 (8)
Mircea_Piturca
Shopify Partner
1494 42 320

I would not mess with the cannonical but rather set a no-index tag

{% if page.handle == 'mattress-store-los-angeles-ca' %}
  <META NAME="ROBOTS" CONTENT="NOINDEX, FOLLOW">
{% endif %}

This should go into <head>.

Same conditional thing can be done with the connonical URL.

Finally—Add variant descriptions to your products
ShopifyHelp1
New Member
3 0 0

Thanks for the help Mircea!

I will probably do both but definitely want to set the canonical tag.

Google is currently favoring the https://blissfulsleep.com/pages/mattress-store-los-angeles-ca page in search results and while noindex may do the trick, canonical will definitely do the trick.

I take it I need this code?

{% if page.handle == 'mattress-store-los-angeles-ca' %}
  <link rel="canonical" href="https://blissfulsleep.com/">
{% endif %}

Just wantd to double check before I input it.

Also, you said not to mess with the canonical tag? Was there a reason why? Was it because now the "https://blissfulsleep.com/pages/mattress-store-los-angeles-ca" page will have two canonical tags? If so, how do I remove the canonical tag on "https://blissfulsleep.com/pages/mattress-store-los-angeles-ca" that just points back to itself? If you check the page currently, there is a canonical tag there that just points right back to "https://blissfulsleep.com/pages/mattress-store-los-angeles-ca".

I hope that's not too confusing?

Thanks for all of your help!

ShopifyHelp1
New Member
3 0 0

Hey Mircea,

Any idea on this?

Iky
Tourist
11 0 3

Yes! I have the same question too!

Can anyone let us know if this code is right and where to paste to

{% if page.handle == 'mattress-store-los-angeles-ca' %}
  <link rel="canonical" href="https://blissfulsleep.com/">
{% endif %}

 

Thanks

Iky

Jason
Shopify Expert
10438 169 2081

The base concept is correct, but you won't be able to just paste that in. Your theme very likely already has code in place setting a canonical url so you don't want to have two tags. You'd want to find that and create and if/else conditional statement so that only the one shows.

 

First locate that section in your theme and reply back with the code - and surrounding parts. Each theme will have that code in a different spot and some seo apps will also add their own version instead. That makes it hard to direct your to the exact spot.

 

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.
Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.
★ http://freakdesign.com.au ★
Iky
Tourist
11 0 3

Thank you very much! I found your reply to another one!

It works perfectly with if/else! Thanks


@Jason wrote:

The base concept is correct, but you won't be able to just paste that in. Your theme very likely already has code in place setting a canonical url so you don't want to have two tags. You'd want to find that and create and if/else conditional statement so that only the one shows.

 

First locate that section in your theme and reply back with the code - and surrounding parts. Each theme will have that code in a different spot and some seo apps will also add their own version instead. That makes it hard to direct your to the exact spot.

 



, Jason! 

MougheesHaider
Shopify Partner
10 0 2

This needs to be pasted just before the closing head tag </head>

SamuelFi
Tourist
8 0 0

Hi Girls and Guys

I am looking for a similar solution, can you give any pointers?

The mention of " if/else" looks exactly like what I am after..

My case is such that the shop has

  • primary domain "shopdomain.com" (A1)
  • with another language version "shopdomain.com/fi"  (A2)
  • plus the owner has set up a thirdparty domain "domainshop.fi" (A3)

All urls under the language version "shopdomain.com/fi"  (A2) are identical to "domainshop.fi" (A3) 

Currently all urls everywhere , under these paths self canonicalise  - for example

  • ex url type A1: shopdomain.com/collections canonicalises to shopdomain.com/collections
  • ex url type A2: shopdomain.com/fi/collections canonicalises to shopdomain.com/fi/collections
  • ex url type A3: domainshop.fi/collections canonicalises to domainshop.fi/collections 

and so on..

What I would ideally like to do is

Leave all canonicals under type A1 intact

Change the canonicals for the urls for the secondary language (A2) to point to the thirdparty domain version (A3)

it would be simply case of if/else where canonical reads

If url contains "shopdomain.com/fi" then canonical targets values are updated so that "shopdomain.com/fi" part is substituted with "domainshop.fi", (with the rest of the string intact); else case simply leaves the canonical tag as is.

So above example urls and their canonical settings would look as follows:

  • ex url type A1: shopdomain.com/collections canonicalises to shopdomain.com/collections (as before)
  • ex url type A2: shopdomain.com/fi/collections canonicalises to domainshop.fi/collections
  • ex url type A3: domainshop.fi/collections canonicalises to domainshop.fi/collections (as before)

Another alternative I could do is just 301 redirect all urls under shopdomain.com/fi to domainshop.fi/

Both solutions are acceptable with first requiring me to address hreflang settings in using the same conditional logic too, the second is simpler in the sense that its just redirects.

Can anyone help me construct the IF/Else code , or just point me to the right place to redirect everything contained under path shopdomain.com/fi (ideally so that the rest of the url string remains intact, in which case shopdomain.com/fi/collections would 301 todomainshop.fi/collections

 

Thanks in advance for any help you can spare.

 

Sami