<p>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.: <code>|first</code> or <code>|last</code>, and you'll also need to <a href="https://docs.craftcms.com/v3/dev/filters.html#replace" rel="nofollow noreferrer">|replace</a> any hyphens and then <a href="https://twig.symfony.com/doc/2.x/filters/capitalize.html" rel="nofollow noreferrer">|capitalize</a> the first letter of the result.</p>

<pre><code>{% set myUri = craft.app.request.segments %}

&lt;title&gt;{{ myUri }}&lt;/title&gt;
</code></pre>

<p>For more on segments: <a href="https://docs.craftcms.com/v3/changes-in-craft-3.html#template-functions" rel="nofollow noreferrer">https://docs.craftcms.com/v3/changes-in-craft-3.html#template-functions</a></p>

CC BY-SA 4.0
2019-02-10T16:24:55.620Z
2019-02-10T16:24:55.620Z
Jon Weedin
<p>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.</p>

CC BY-SA 4.0
2019-02-14T02:43:58.483Z
Can you give an example, using a URI and then the Title you would like to see?
Roi Agneta
<craft3><php>
Custom title using URI segment
# Custom title using URI segment

(Asked by: username_0 on 2019-02-10)

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.

**Tags:** craft3, php

> **Comments:**
> **username_1**: Can you give an example, using a URI and then the Title you would like to see?  

---

## 1 answers

### Answer by username_2 on 2019-02-10. Score: 1

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 %}

{{ myUri }}

For more on segments: https://docs.craftcms.com/v3/changes-in-craft-3.html#template-functions


---

