Does Google read dynamic canonical tags?
-
Does Google recognize rel=canonical tag if loaded dynamically via javascript? Here's what we're using to load:
<script> //Inject canonical link into page head if (window.location.href.indexOf("/subdirname1") != -1) { canonicalLink = window.location.href.replace("/kapiolani", ""); } if (window.location.href.indexOf("/subdirname2") != -1) { canonicalLink = window.location.href.replace("/straub", ""); } if (window.location.href.indexOf("/subdirname3") != -1) { canonicalLink = window.location.href.replace("/pali-momi", ""); } if (window.location.href.indexOf("/subdirname4") != -1) { canonicalLink = window.location.href.replace("/wilcox", ""); } if (canonicalLink != window.location.href) { var link = document.createElement('link'); link.rel = 'canonical'; link.href = canonicalLink; document.head.appendChild(link); } script>
-
I believe it's a limitation of our CMS. I'll see if we can try it in htaccess or PHP. Thanks for the insight.
-
Thanks for the reply. Doesn't appear Google is recognizing the tag because duplicate pages with it are still showing up in SERPs.
-
I Wouldn't bet on that working. Why not use the exact same code in .htaccess format, or even PHP? Javascript is a coding language that is parsed after the window starts loading, it's not like PHP where it gets parsed before the load.
Thanks
-
Hi SoulSurfer,
Read This http://searchengineland.com/tested-googlebot-crawls-javascript-heres-learned-220157
The google bot was able to read rel=nofollow and links were not followed. So I would think the same for rel=canonical as well.
Thanks,
Don
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Does "google selected canonical" pass link juice the same as "user selected canonical"?
We are in a bit of a tricky situation since a key top-level page with lots of external links has been selected as a duplicate by Google. We do not have any canonical tag in place. Now this is fine if Google passes the link juice towards the page they have selected as canonical (an identical top-level page)- does anyone know the answer to this question? Due to various reasons, we can't put a canonical tag ourselves at this moment in time. So my question is, does a Google selected canonical work the same way and pass link juice as a user selected canonical? Thanks!
Technical SEO | | Lewald10 -
Google indexing is slowing down?
I have up to 20 million unique pages, and so far I've only submitted about 30k of them on my sitemap. We had a few load related errors during googles initial visits, and it thought some were duplicates, but we fixed all that. We haven't gotten a crawl related error for 2 weeks now. Google appears to be indexing fewer and fewer urls every time it visits. Any ideas why? I am not sure how to get all our pages indexed if its going to operate like this... love some help thanks! HnJaXSM.png
Technical SEO | | RyanTheMoz0 -
Will canonical solve this?
Hi all, I look after a website which sells a range of products. Each of these products has different applications, so each product has a different product page. For eg. Product one for x application Product one for y application Product one for z application Each variation page has its own URL as if it is a page of its own. The text on each of the pages is slightly different depending on the application, but generally very similar. If I were to have a generic page for product one, and add canonical tags to all the variation pages pointing to this generic page, would that solve the duplicate content issue? Thanks in advance, Ethan
Technical SEO | | Analoxltd0 -
Google Dancing?
Hello, I was wondering why my website for some keywords goes from 2nd 3rd page in Google to 7th or even more sometimes? This happens since a while. Any suggestion? Thanks. Eugenio
Technical SEO | | socialengaged0 -
Canonical Tag on Blog - Roger says it's incorrect?
Hi I have just released a post on my blog and I wanted to check my primary keyword for the post to make sure the page scores well. However when I did the page report it showed the Canonical Rel tag was incorrect. example of link the blog is http://www.example.com/Blog/post-comment/ The Canonical tag is below What am I doing wrong, as it looks correct to me?
Technical SEO | | Cocoonfxmedia0 -
0 Google Backlinks
A sudden drop in the number of google backlinks. Earlier this month I had 15 google backlinks and now all of a sudden I have none. My google impression has also dropped drastically, my website's average is 10000 impression per day and now we have none. I have increased the crawler's speed on the website, would this be the cause of it? 4pmdesign.com
Technical SEO | | 4pm0 -
Google penalty
Anyone have any success stories on what they did to get out of Google penalty?
Technical SEO | | phatride0 -
Wrong Title Tag & No Meta Description showing up in Google SERP's
I'd like to know what I can do to get the correct title tag + meta description that I have on the page for www.myescondidomovers.com/ to actually show up in the SERP's on Google? It's currently just showing my main keyword and the domain name, nothing else. See attached and thanks in advance for you help. Much appreciated. SERPS.png
Technical SEO | | afranklin0