What is the best way of creating a custom field for each page whereby the user can input a URL into a field, which then gets input into a rel=canonical element like the example below.

<link rel="canonical" href="{{URL_FROM_CUSTOM_FIELD}}">

I already have an SEO tab like in the image below, however I am unsure of how to create a custom field inside this tab.

enter image description here

If someone could point me in the right direction, that would be great, as I am very new to the CMS.


First, I would recommend looking at the SEOmatic plugin - it does all of this for you, and a whole lot more.

If you want to go it on your own, though, I would just use {{ craft.request.url }} rather than adding your own field. Craft already knows what the URL is.

| improve this answer | |
  • Thanks for that, I'll have a look at the plugin. As for craft.request.url, I need to be able to put in url's for other pages rather than the same page. Any solution to that? Thanks – GraMas Jun 23 '17 at 6:34
  • 1
    {{ craft.request.url }} uses the current URL. so, it will produce different results for www.site.com and site.com, thus defeating the purpose of canonical links. – aaandre Nov 19 '18 at 7:50
  • terrible answer. as @aaandre said this defeats the purpose of the tag. – Rick Kukiela Jan 31 at 6:17

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.