The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Technical SEO Issues
    4. Does Google read dynamic canonical tags?

    Does Google read dynamic canonical tags?

    Technical SEO Issues
    5 3 519
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SoulSurfer8
      SoulSurfer8 last edited by

      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>
      
      1 Reply Last reply Reply Quote 0
      • donsilvernail
        donsilvernail last edited by

        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

        SoulSurfer8 1 Reply Last reply Reply Quote 1
        • andy.bigbangthemes
          andy.bigbangthemes last edited by

          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

          SoulSurfer8 1 Reply Last reply Reply Quote 1
          • SoulSurfer8
            SoulSurfer8 @donsilvernail last edited by

            Thanks for the reply. Doesn't appear Google is recognizing the tag because duplicate pages with it are still showing up in SERPs.

            1 Reply Last reply Reply Quote 0
            • SoulSurfer8
              SoulSurfer8 @andy.bigbangthemes last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              • Google Search Console and User-declared canonical is actually Hreflang tag
                katemorris
                katemorris
                0
                2
                1.3k

              • If Google's index contains multiple URLs for my homepage, does that mean the canonical tag is not working?
                Dr-Pete
                Dr-Pete
                0
                4
                217

              • Duplicate pages in Google index despite canonical tag and URL Parameter in GWMT
                Dr-Pete
                Dr-Pete
                0
                5
                2.1k

              • Duplicate Title Tags and Meta Desc even with the correct Canonical Tag
                bhalverson
                bhalverson
                0
                5
                809

              • Canonical tags
                Jake-a-boo
                Jake-a-boo
                1
                6
                1.2k

              • Canonical Tag Here?
                Dr-Pete
                Dr-Pete
                0
                4
                566

              • Google showing former meta tags in search results inspite of new tags being crawled by it
                sesertin
                sesertin
                0
                3
                558

              • Canonical tags and internal Google search
                RyanPurkey
                RyanPurkey
                0
                3
                914

              Get started with Moz Pro!

              Unlock the power of advanced SEO tools and data-driven insights.

              Start my free trial
              Products
              • Moz Pro
              • Moz Local
              • Moz API
              • Moz Data
              • STAT
              • Product Updates
              Moz Solutions
              • SMB Solutions
              • Agency Solutions
              • Enterprise Solutions
              • Digital Marketers
              Free SEO Tools
              • Domain Authority Checker
              • Link Explorer
              • Keyword Explorer
              • Competitive Research
              • Brand Authority Checker
              • Local Citation Checker
              • MozBar Extension
              • MozCast
              Resources
              • Blog
              • SEO Learning Center
              • Help Hub
              • Beginner's Guide to SEO
              • How-to Guides
              • Moz Academy
              • API Docs
              About Moz
              • About
              • Team
              • Careers
              • Contact
              Why Moz
              • Case Studies
              • Testimonials
              Get Involved
              • Become an Affiliate
              • MozCon
              • Webinars
              • Practical Marketer Series
              • MozPod
              Connect with us

              Contact the Help team

              Join our newsletter
              Moz logo
              © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
              • Accessibility
              • Terms of Use
              • Privacy