Categories: SEO

Google documents how to inject canonical tags using JavaScript

Google has updated its JavaScript SEO help document to add technical details on how to inject canonical link tags using JavaScript. Google added a new section titled “properly inject rel=”canonical” link tag.”

What is new. Here is the new section where Google recommends not to implement your canonical tags using JavaScript, but if you must, Google explains this is the proper way to do so. Google wrote:

While we don’t recommend using JavaScript for this, it is possible to inject a rel=”canonical” link tag with JavaScript. Google Search will pick up the injected canonical URL when rendering the page. Here is an example to inject a rel=”canonical” link tag with JavaScript:

Google added this warning stating “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.”

Hit or miss. We have seen cases where Google can pick up these canonical tags or other embedded elements, even structured data, using JavaScript. But it can be hit or miss, so it is recommended that if you are going to use JavaScript specifically to inject your canonical tags, follow these directions precisely.

Why we care. Again, if you are injecting canonical tags using JavaScript, Google has finally officially documented the proper way to implement it. So check the documentation over here and make sure your implementation follows Google’s recommendations.


New on Search Engine Land

About The Author

Barry Schwartz a Contributing Editor to Search Engine Land and a member of the programming team for SMX events. He owns RustyBrick, a NY based web consulting firm. He also runs Search Engine Roundtable, a popular search blog on very advanced SEM topics. Barry can be followed on Twitter here.

FOLLOW US ON GOOGLE NEWS

 

Read original article here

Denial of responsibility! Search Engine Codex is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – admin@searchenginecodex.com. The content will be deleted within 24 hours.

Share
Chris Barnhart

Leave a Comment
Published by
Chris Barnhart

Recent Posts

What Is Google Clamping Down On? Spring 2024 Updates — Whiteboard Friday

So one of them is a lot of SEOs right now, and a lot of…

May 5, 2024

Daily Search Forum Recap: May 3, 2024

Here is a recap of what happened in the search forums today, through the eyes…

May 4, 2024

The Best Times to Post on Instagram for Maximum Engagement: Unlocking Secrets

Navigating the world of Instagram posting involves many considerations, but one crucial aspect is timing…

May 4, 2024

The Industry Mourns The Loss Of Mark Irvine

I am deeply sad to report that Mark Irvine passed away unexpectedly last night. Mark…

May 3, 2024

Google AdSense Removed Privacy Policy As Place To Withdraw Consent

Google AdSense has removed reference to your privacy policy as a place to withdraw consent.…

May 3, 2024

Google SGE AI Answers Cost 80% Less To Generate Now

One of the big worries for Google investors was the cost of running AI to…

May 3, 2024