Developer forum

Forum » CMS - Standard features » How to overwrite Canonical Link

How to overwrite Canonical Link

Lara Arsénio
Reply

Hello. I need to customize the canonical <link> in meta tags - adding the absolute URL instead of relative, and other specific change for product Pages.

How can I override it, given the fact that it is returned in a single field  "MetaTags" altogether with other meta information.

Notice that I did disabled the Setting "UseCanoncial" but the link canonical remains visible.


Replies

 
Nicolai Pedersen
Reply

Hi Lara

You have settings in 2 places - the URL settings page and there is also a setting on the paragraph - see dump, and remove both to get rid of the canonical.

You can set your own canonical before the PageView.Output like this:

Pageview.Meta.AddTag("customCan", "<link rel=\"canonical\" href=\" + HttpUtility.HtmlAttributeEncode(Converter.ToString(Page.MetaCanonical)) & "\"">")
Capture.PNG
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Nicolai,

We tried adding our own using Pageview.Meta.AddTag but couldn't make it work. Can we do that from a template or does it has to be from code like a subscriber?

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Depends on which template and if it is using tags or viewmodels... It should work if you do this from a ecommerce template on a paragraph. it will not work from a master template as that is executing and therefore already parsed the metatags...

And it has to have this:

Pageview.Meta.AddTag("customCan", "")
Votes for this answer: 2
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Yeah, in the code I found the references to customCan so we used that already. But I am pretty sure we tried it in a master so that would explain why it didn't work. We'll try again in a different template.

Thanks!

 
Lara Arsénio
Reply

Defining the .AddTag("customCam") from inside ecommerce template / paragraph solved the problem.

Thanks!

 

You must be logged in to post in the forum