I am working on my SEO and I am getting a duplicate title in Craft. I want to make a custom title using the URI segment in using PHP.
1 Answer
You can use something like this in your main layout template. You'll need to add a filter after "segments" to get the URI segment you want, e.g.: |first
or |last
, and you'll also need to |replace any hyphens and then |capitalize the first letter of the result.
{% set myUri = craft.app.request.segments %}
<title>{{ myUri }}</title>
For more on segments: https://docs.craftcms.com/v3/changes-in-craft-3.html#template-functions