How to Add a Canonical Link Element to Concrete5

Adding a canonical link element to your Concrete5 website is actually pretty straight forward. What I’ve done is add a few simple lines of code to my header.php template file:
<?php
$url=Loader::helper('navigation');
$canonical=$url->getCollectionURL($c);
$canonical=preg_replace("/index.php\?cID=1$/","",$canonical);
?>
<link rel="canonical" href="<?php echo $canonical; ?>" />

I wish I could take credit for this code, but I can’t – the Concrete5 Community is where I found this bit of code from “pinkboi” and guess what, it works like a charm with pretty URL’s!

What is a Canonical Link Element?

In the vast online world of the internet there are millions of dynamic websites. Sometimes on these sites, the exact same exact content ends up getting generated across multiple pages. This is very bad for SEO purposes. For example, you could actually have several different URL’s for the same webpage if your server or CMS isn’t set up properly:

  • apheus.com
  • www.apheus.com
  • apheus.com
  • www.apheus.com/
  • apheus.com/index.php
  • www.apheus.com/index.php

All of those URL’s point to the same document – which means that they show up as duplicate content in the eyes of the search engines. Duplicate content is a killer and in the example shown above, which page will the search engine return? Google, Yahoo and Microsoft have adopted a way to combat this problem – with the canonical link element. This single line of code is added between the <head> tags of HTML and identifies a single page as the “real” page containing the content. For example:
<link rel="canonical" href="http://www.myapheus.com/" />
Canonical link elements are not a fix-all for every duplicate content issue. Webmasters should make every effort to fix the problems with their website or hire a web professional (like me!) to help solve your duplicate content problems. Not every website can be fixed upstream, so that’s where the canonical link element comes into play. For a full explanation of canonical links, check out Matt Cutts’ video on the subject:

3 Responses to “How to Add a Canonical Link Element to Concrete5”

  1. Ron says:

    I was told my site has a duplicate content problem. Can you tell if it does and if it can be fixed? We added the canonical link a while back. But I'm still being told I have a problem.

  2. Georgi says:

    Our organization practises for more than 10 years in laser scission and manifacture of hand made parts from stainless. The firm has a high proficiency in the production of high quality details, welded design and metal pieces made of stainless steel.

Leave a Reply