Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

Canonical and googlebot

         

designergweb

1:12 pm on Jul 25, 2019 (gmt 0)



Why my canonical doesnt readed from googlebot or seo spider programm. I used this code
<script type="text/javascript">
var link = document.createElement('link');
link.setAttribute('rel', 'canonical');
link.setAttribute('href', location.protocol + '//' + location.host + location.pathname);
document.head.appendChild(link);
</script>
<link rel="canonical" href="example.com/tested/">

Dimitri

3:14 pm on Jul 25, 2019 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Not all bots execute Javascript, and for the others, it's possible that Javascript is evaluated after processing <head>. So, in other words, it's possible that, when you are adding a meta tag in Javascript , a robot is already done processing the <head> parameters.

designergweb

6:25 am on Jul 26, 2019 (gmt 0)



The best practises for canonical ?The best position?

lucy24

6:34 am on Jul 26, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The best practises for canonical
The best practice is to design the site so each page is reachable by only one URL, obviating any need for “canonical”. You're really asking about second-best practices.

Dimitri

1:38 pm on Jul 26, 2019 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Indeed, and it doesn't make sense to populate the canonical meta tag in Javascript! If , for all kind of reasons, the page is generated from different URLs, the Javascript will produce different canonical for each URL, which is not the goal.

designergweb

6:41 am on Jul 30, 2019 (gmt 0)



So i must to used only <link rel="canonical" href="example.com/tested/"> without <script type="text/javascript">
var link = document.createElement('link');
link.setAttribute('rel', 'canonical');
link.setAttribute('href', location.protocol + '//' + location.host + location.pathname);
document.head.appendChild(link);
</script> ?

phranque

8:23 am on Jul 30, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



So i must to used only <link rel="canonical" href="example.com/tested/"> ... ?

yes

designergweb

8:35 am on Jul 30, 2019 (gmt 0)



thanks a lot!