SOLVED

Set Canonical URL via Javascript on all Marketo LPs

Go to solution
Yavor_Todorov
Level 2

Set Canonical URL via Javascript on all Marketo LPs

Hello, what we are trying is to add the canonical tag on our Marketo landing pages.

 

First, I used this:

<link rel="canonical" href="{{my.Page Canonical URL}}"/>

Then I created the actual token in my program and I put the link inside. Then I pasted the above code in my LP Custom Head HTML and it worked. 

 

As we are creating a lot of pages, someone could possibly forget to update the URL within the token, so can we add the above line with JS dynamically? I tried to use this script https://gist.github.com/krschmidt/9d46d1d080454b55f8cf , but the <link> doesn't show up in the source code and also people are not 100% sure if Google will count this.

 

My hope is to have such script and add it to our landing page template. This way it should work automatically, without tokens or interference from our side.

 

Thanks,

Yavor

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Set Canonical URL via Javascript on all Marketo LPs


Then I pasted the above code in my LP Custom but the <link> doesn't show up in the source code 

Because it’s by definition not in the initial HTML document. You’re injecting it into the DOM later.

 

Honestly I wouldn’t do this belt-and-suspenders approach. You’re just making it easier for people to forget procedures. And as you said it isn’t clear that Google takes the injected link correctly or consistently.

View solution in original post

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Set Canonical URL via Javascript on all Marketo LPs


Then I pasted the above code in my LP Custom but the <link> doesn't show up in the source code 

Because it’s by definition not in the initial HTML document. You’re injecting it into the DOM later.

 

Honestly I wouldn’t do this belt-and-suspenders approach. You’re just making it easier for people to forget procedures. And as you said it isn’t clear that Google takes the injected link correctly or consistently.

View solution in original post