How To Add Canonical and HREFLANG Markup To Your Site Using JavaScript

Category: Javascript, SEO

Recently I joined a google webmaster central office hours hangout where I asked the question:

“…is implementing hreflang and then modifying a canonical tag using JavaScript. So you see that being an issue or something that Google would recognize?”

John replied suggesting that it “could work” however instead of swaping canonical or hreflang tags between static HTML and rendered HTML, ensure the static HTML version would not have those signals from the start and insert them using JavaScript.

“What I might do in a case like that is just not provide a canonical in the static HTML version and then add one with JavaScript, so that signal is clear, like, this is the only signal that we have”

My question recently got featured in an article on SEO Round Table so I’m happy to see this answer may help out other SEO’s as well! Below is the video

Posted by Darcy Burk

Darcy Burk launched Burk Digital Factory after 15+ years in the digital marketing space. His extensive knowledge of search engine optimization enables him to help local and online businesses achieve their goals.