How to display tags by their name as entered in the field

I use Str::slug($tag) to have lowercase slugs for tags :+1:

<?php foreach ($tags as $tag): ?>
  <li><a href="<?= url($page->parent(), ['params' => ['tag' => Str::slug($tag)]]) ?>"><?= $tag ?></a></li>
<?php endforeach ?>

But now on the parent page where posts are filtered by the clicked tag, the tag name is displayed as the slug. A tag named “Good Day” will now be shown as “good-day” :thinking:

<?php if ($tag = param('tag')): ?>
  <h1><?= $tag ?></h1>
<?php else: ?>
...

Instead of sluggifying the tag, I’d suggest you urlencode() and urldecode() them again.

1 Like

Thanks!