March 13, 2016

Adding canonical links to Cryogen

I'm currently in the process of adding HTTPS support to this site (if you haven't been redirected you can check it out here)

As I was doing this I wanted to check to make sure that my pages were using the HTTPS version of their URL as the canonical link. That's when I noticed that there wasn't any canonical link at all. That's no good! 1

No worries though because this is pretty easy to fix. All we need to do is add the following line to base.html in whatever theme you are using:

<link rel="canonical" href="{{site-url}}{{uri}}">


So for example the content in your base.html may now look like:

  <head>
     <meta charset="utf-8"/>
     <title>{{title}}{% block subtitle %}{% endblock %}</title>
     <link rel="canonical" href="{{site-url}}{{uri}}">
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <link href='http://fonts.googleapis.com/css?family=Alegreya:400italic,700italic,400,700' rel='stylesheet'
           type='text/css'>


This has been merged in to Cryogen on GitHub so once Clojars has been update to the newest version anyone creating a new Cryogen project won't need to do this.

Links

  1. Yoast has a great article about why we want to have a canonical linkon all of our pages.
Tags: Cryogen Clojure SEO