Create custom field to input canonical url in a page

Craft CMS Asked by GraMas on March 10, 2021

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.

One Answer

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.

Answered by Patrick Harrington on March 10, 2021

Add your own answers!

Related Questions

htaccess www to non-www with subdomain

1  Asked on July 11, 2021 by plaintxt


Getting average of number field values

1  Asked on July 11, 2021


Checkout Without Payment

1  Asked on July 9, 2021 by taher


SQL Queries Performing Full Table Scan

0  Asked on July 4, 2021 by zhua89


LDAP connects but fails to return entries

0  Asked on June 28, 2021


Is there a “sticky post” function built into Craft?

2  Asked on June 28, 2021 by steve-adams


Craft 3 Hosting on Azure

0  Asked on June 27, 2021


Specify a specific entry type in paramaters

2  Asked on June 24, 2021 by weslawson


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir