Set Canonical URL via Javascript on all Marketo LPs | Community
Skip to main content
New Participant
October 6, 2021
Solved

Set Canonical URL via Javascript on all Marketo LPs

  • October 6, 2021
  • 1 reply
  • 2184 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

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.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
October 6, 2021

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.