Google Explains How To Inject Canonical Tags Using JavaScript In Updated Doc

Jun 30, 2022 - 7:11 am 0 by

Google Mirror

Google has updated its JavaScript SEO help document to add a new section on how to properly inject canonical link tags using JavaScript. The document says Google does not recommend using JavaScript for this, however "it is possible to inject a rel=canonical link tag with JavaScript."

The help document adds that "Google Search will pick up the injected canonical URL when rendering the page."

A note Google made is that "when using JavaScript to inject the rel="canonical" link tag, make sure that this is the only rel="canonical" link tag on the page. Incorrect implementations might create multiple rel="canonical" link tag or change an existing rel="canonical" link tag. Conflicting or multiple rel="canonical" link tags may lead to unexpected results."

Here is a code example of how to do this:

Google Inject Canonical Tags Using Javascript

Previously, as Google is doing now, Google warned against doing it this way but did say it can work.

Forum discussion at Twitter.

 

Popular Categories

The Pulse of the search community

Follow

Search Video Recaps

 
Google March Core Update Done, HCU Recoveries, Site Reputation Abuse & AI Topics - YouTube
Video Details More Videos Subscribe to Videos

Most Recent Articles

Search Forum Recap

Daily Search Forum Recap: May 3, 2024

May 3, 2024 - 4:00 pm
Search News

The Industry Mourns The Loss Of Mark Irvine - Brilliant & Giving Search Marketer

May 3, 2024 - 1:10 pm
Search Video Recaps

Search News Buzz Video Recap: Google March Core Update Done, HCU Recoveries, Site Reputation Abuse & AI Topics

May 3, 2024 - 8:01 am
Google

Google SGE AI Answers Now Cost 80% Less To Generate

May 3, 2024 - 7:51 am
Google Search Engine Optimization

Google Open To Alternative Ideas For Hreflang

May 3, 2024 - 7:41 am
Google Search Engine Optimization

Google Recrawls URLs At Different Rates: Multiple Times Per Day To Every Few Months

May 3, 2024 - 7:31 am
Previous Story: Quiet Green Area At Google Brussels Office