<p><strong>Edited</strong></p>

<p>I just learned this, but as of Craft 2.4, there's a <a href="https://craftcms.com/docs/templating/filters#kebab" rel="nofollow"><code>kebab</code> filter</a> which you can use here. This would probably give you the effect you're after, where the string "two words" would become "two-words", and punctuation characters are dropped by default.</p>

<p>You could use this like so:</p>

<pre><code>&lt;li&gt;&lt;a href="{{ siteUrl }}tags/{{ tag.title | kebab }}"&gt;{{ tag.title }}&lt;/a&gt;&lt;/li&gt;
</code></pre>

<hr>

<p><strong>Original</strong></p>

<p>The <code>%20</code> string is being added to replace spaces because you're using the <code>url_encode</code> filter on <code>tag.title</code>. A simple (though somewhat naïve) way to to solve this would be to use the replace filter:</p>

<pre><code>{{ tag.title | url_encode | replace({"%20": "-"}) }}
</code></pre>

<p>However, you might still see some "%XX" characters in this string if the <code>tag.title</code> has other characters that url_encode might want to replace. The "%" character, for example, gets turned into "%25" after being run through <code>url_encode</code>.</p>

<p>This also probably won't do what you expect, as the link you're generating for the tag won't work unless you're doing special routing. The problem stems from the fact that tags don't have clean URL slugs at this time, so what you're doing right now is probably the best course of action.</p>

<p>You've probably already seen this, but there's a <a href="http://buildwithcraft.com/help/tag-urls" rel="nofollow">documentation page specially about linking to tags</a>. This is the current best practice I know of. If you're really looking for cleaner slugs in URLs, I'd recommend using categories instead of tags if possible.</p>

CC BY-SA 3.0
2015-01-28T18:11:12.840Z
2016-07-06T23:00:24.770Z
2016-07-06T23:00:24.770Z
Gavin Anderegg
<p>I'm building a site where I am linking entries based on their tags. If you click on a tag you go to a dedicated page with all entries that share the same tag.</p>

<pre><code>{% for tag in craft.tags.relatedTo(entry) %}
    &lt;li&gt;&lt;a href="{{ siteUrl }}tags/{{ tag.title | url_encode }}"&gt;{{ tag.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
</code></pre>

<p>The problem I have is that if a tag has more than 1 word, the URL displays like this:</p>

<p><code>http:/site.com/tag/two%20words</code></p>

<p>How do I change "%20" to a dash?</p>

CC BY-SA 3.0
2016-07-15T16:41:47.307Z
I've updated my answer below. I'm not sure if you're still having your issue, but would this have solved it?
Gavin Anderegg
<templating><url><tags><siteurl>
How do I make the "%20" in URL's show as "-"
# How do I make the "%20" in URL's show as "-"

(Asked by: username_0 on 2015-01-28)

I'm building a site where I am linking entries based on their tags. If you click on a tag you go to a dedicated page with all entries that share the same tag.
{% for tag in craft.tags.relatedTo(entry) %}
    {{ tag.title }}
{% endfor %}

The problem I have is that if a tag has more than 1 word, the URL displays like this:
http:/site.com/tag/two%20words
How do I change "%20" to a dash?

**Tags:** templating, url, tags, siteurl

> **Comments:**
> **username_1**: I've updated my answer below. I'm not sure if you're still having your issue, but would this have solved it?  

---

## 1 answers

### Answer by username_1 on 2015-01-28. Score: 6 | Accepted answer

Edited
I just learned this, but as of Craft 2.4, there's a kebab filter which you can use here. This would probably give you the effect you're after, where the string "two words" would become "two-words", and punctuation characters are dropped by default.
You could use this like so:
{{ tag.title }}


Original
The %20 string is being added to replace spaces because you're using the url_encode filter on tag.title. A simple (though somewhat naïve) way to to solve this would be to use the replace filter:
{{ tag.title | url_encode | replace({"%20": "-"}) }}

However, you might still see some "%XX" characters in this string if the tag.title has other characters that url_encode might want to replace. The "%" character, for example, gets turned into "%25" after being run through url_encode.
This also probably won't do what you expect, as the link you're generating for the tag won't work unless you're doing special routing. The problem stems from the fact that tags don't have clean URL slugs at this time, so what you're doing right now is probably the best course of action.
You've probably already seen this, but there's a documentation page specially about linking to tags. This is the current best practice I know of. If you're really looking for cleaner slugs in URLs, I'd recommend using categories instead of tags if possible.


---

