1

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.

1

If you truly want to this via a custom field:

  1. Admin > Settings > Fields is where you create custom fields.
  2. Settings > Sections > Edit Entry Type is where you assign custom fields to your section. You drag and drop the field under "Design Your Field Layout".
  3. You can then output the custom field in your template using {{ entry.customFieldHandle }} for example.

A more common approach would be to code this tag in your templates instead of using a custom field. I can't give you a very specific approach to try with the code since I do not know your site structure and desired result.

0

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.

3
  • 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 – Gazz 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 '20 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.