2

The canonical link element isn't set for all pages. For example, if I look at the source code for a post, I can see the following in the <head>:

<link rel='canonical' href='http://example.com/post-name/' />

However, if I look at the source code for an author archive page, I don't see the link element.

Why isn't the canonical link element used for all pages?

Reference

I've included below the function used by WordPress to output the canonical link element.

/**
 * Output rel=canonical for singular queries.
 *
 * @since 2.9.0
*/
function rel_canonical() {
    if ( !is_singular() )
        return;

    global $wp_the_query;
    if ( !$id = $wp_the_query->get_queried_object_id() )
        return;

    $link = get_permalink( $id );

    if ( $page = get_query_var('cpage') )
        $link = get_comments_pagenum_link( $page );

    echo "<link rel='canonical' href='$link' />\n";
}
4
  • what would the canonical link to an author archive be? if it pointed to itself, and contained content from a post which also had a canonical link which pointed to itself, you then have a duplicate content issue.
    – Milo
    Oct 13 '14 at 2:48
  • That's why you should always use the excerpt instead of the content on archive pages. IMO Oct 13 '14 at 2:51
  • I'm surprised this issue hasn't attracted more interest. The canonical is always defined on the <head> so there would be no conflict between posts and categories anyway.
    – IXN
    Nov 9 '17 at 1:17
  • The canonical is used to point to the ... well, canonical url. It indicates this is a unique-content url. So a paginated archive for example should point all the paginated items to themselves of course, as those aren't duplicates ... and there won't be any issue with "duplicate content" since the content on an archive is NOT the same as on a single post, it may contain some of it, but never just the content of a single post. It is a mistery that WP does not add it, it should, and there are plenty plugins doing it for you. So, the answers "it shouldn't be done" are wrong. May 4 at 12:31
0

It's not like every single page is magically better with canonical link. The technical purpose of canonical link is to de–duplicate identical or nearly–identical content at different URLs.

It doesn't make sense for archives because they are :

  • collections of content
  • moving target, what is on front page or archive right now won't be there after new posts are made

While it would make sense to add canonical for some archive implementations, it doesn't fit typical WordPress archives well.

1
  • My understanding is the preferred (canonical) URL is also used in tracking (Google Analytics for example). It is in this scenario that I can see some benefit to using a canonical link element on archive pages. (i.e consolidated page statistics) Oct 13 '14 at 19:10
0

Because permalinks refer to singular posts and not taxonomy or archive type of pages. It is possible to create the canonical links for them too, but it is a different code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.