<p>Basically not possible with Craft, currently.</p>
<p>Slugs go through a <a href="https://github.com/craftcms/cms/blob/develop/src/helpers/ElementHelper.php#L100-L124" rel="nofollow noreferrer">normalizeSlug()</a> helper that removes what it thinks is HTML and inner-word punctuation.</p>
<p>What I suspect is tripping you up is when it splits on &quot;words&quot; here: <a href="https://github.com/craftcms/cms/blob/develop/src/helpers/ElementHelper.php#L121" rel="nofollow noreferrer">https://github.com/craftcms/cms/blob/develop/src/helpers/ElementHelper.php#L121</a></p>
<p>Where only <code>.</code>, <code>|</code> and <code>-</code> are allowed punctuation, stripping out everything else.</p>

CC BY-SA 4.0
2021-06-01T23:59:18.913Z
2021-06-03T03:50:32.320Z
2021-06-03T03:50:32.320Z
Brad Bell
<p>I need to output a slug that will include characters like &lt; and |. I realise that these can't be literal, so I had hoped to be able to swap them out for the URL encoded equivalents.</p>
<p>For example, the slug <code>l&lt;t</code></p>
<p>Would become: <code>l%3Ct</code></p>
<p>Right now, though, if I actually try and save the entry it strips out all of the percent symbols (<code>%</code>) rendering the encoding useless. Is there a way to turn off this behaviour? Or escape the symbols somehow?</p>

CC BY-SA 4.0
2021-06-01T19:20:52.333Z
Just curious as to your use case for this? If they are being used as URLs, you usually want them short and straightforward…
RitterKnight
CC BY-SA 4.0
2021-06-01T19:48:33.410Z
I'm building a database, where the slug should be the product name. Some products have these kinds of characters in their names, which would ideally be represented in the URL. If the slug could accept URI encoded characters, then it'll all work nicely, as browsers will interpret the real characters correctly. (If that last part doesn't sound like I would work, I should mention that I don't serve anything direct from Craft, but via the Elements API, so it does indeed work.)
theAdhocracy
<slug><entry-slug>
Special Characters in Slugs
# Special Characters in Slugs

(Asked by: username_0 on 2021-06-01)

I need to output a slug that will include characters like < and |. I realise that these can't be literal, so I had hoped to be able to swap them out for the URL encoded equivalents.

For example, the slug `l`

Would become: `l%3Ct`

Right now, though, if I actually try and save the entry it strips out all of the percent symbols (`%`) rendering the encoding useless. Is there a way to turn off this behaviour? Or escape the symbols somehow?

**Tags:** slug, entry-slug
> **Comments:**
> **username_1**: Just curious as to your use case for this? If they are being used as URLs, you usually want them short and straightforward…  
> **username_0**: I'm building a database, where the slug should be the product name. Some products have these kinds of characters in their names, which would ideally be represented in the URL. If the slug could accept URI encoded characters, then it'll all work nicely, as browsers will interpret the real characters correctly. (If that last part doesn't sound like I would work, I should mention that I don't serve anything direct from Craft, but via the Elements API, so it does indeed work.)  

---

## 1 answers

### Answer by username_2 on 2021-06-01. Score: 2 | Accepted answer

Basically not possible with Craft, currently.

Slugs go through a [normalizeSlug()](https://github.com/craftcms/cms/blob/develop/src/helpers/ElementHelper.php#L100-L124) helper that removes what it thinks is HTML and inner-word punctuation.

What I suspect is tripping you up is when it splits on "words" here: <https://github.com/craftcms/cms/blob/develop/src/helpers/ElementHelper.php#L121>

Where only `.`, `|` and `-` are allowed punctuation, stripping out everything else.


---

