Tags with spaces

Hey guys,

I’m trying to use tags with spaces in my site (e.g. “gordon freeman”). What kirby or my used template (Baltrum) generates is an URL like: /tag:gordon+freeman. Like this, of course, kirby doesn’t find any post, only if it has two tags “gordon” and “freeman”.

Any suggestions to this?

Thanks in advance!

Use urlencode() and urldecode(), e.g.


Thanks for your quick answer!

urlencode() and urldecode() is already used. See https://github.com/getkirby/plugins/blob/master/tagcloud/tagcloud.php.

Any further suggestions?

Try rawurlencode() and rawurldecode(), then …

Thanks again! But this also didn’t work.

Now the system gives me a link like site.tld/tag:gordon freeman
And on the result page it says “Posts tagged with ”gordon%20freeman“”, but still no results.

I guess it must be the built in URL interpreter of kirby.

Any further suggestions?

Could you post your code? I have been using tags with spaces without any problems in the past using urlencode() and urldecode() and with the tagcloud plugin that should work automatically anyway.

Thanks for the info that tags with spaces usually work in kirby!

That brought me to looking into the template files of my applied theme. There the author forgot to use urldecode(). I just added it and now it works fine:

/* Filter by tag, if needed */
if(param('tag', false)) {
    $posts = $posts->filterBy('tags', urldecode(param('tag')), ',');

Thanks again for your help!

1 Like

I am running into a similar issue. I have implemented urldecode and urlencode.

For example, for a category called Alpha Beta the encoded url is:


When I click on that link, the browser loads the address


And at this point I get a generic browser window error saying:

This page isn’t working
localhost redirected you too many times.
Try clearing your cookies.

My controller code is:

return function($site, $pages, $page) {

  $collection = page('collection')->children()->visible();

  if ($tag = urldecode(param('category'))) {
    $collection = $collection->filterBy('tag', $tag, ',');

  return compact('collection', 'tag');


The code that generate the link in my nav is:

<div class="nav">
    <?php foreach($tags as $tag): ?>
        <a class="nav__link" href="<?= url('category:' . urlencode($tag['name']))?>">
          <?php echo $tag['name'] ?>
    <?php endforeach ?>

Have you tried with rawurlencode() and rawurldecode() instead?

I didn’t try rawurlencode().
I have instead create a new clone of a fresh kirby starterkit and tested that categories with spaces do work correctly.
After I rewrote the new installation using my old code. So far it’s working. It must have been some other error that was triggering ERR_TOO_MANY_REDIRECTS.

I have also the same problem with Umlauts (ü,ä,ö) but i cant’t find a way for that. I tried both rawurldecode() and urldecode()…do you have any ideas?

URL example: tld.com/farbe:Türkis

  <a <?php if(rawurldecode(param('farbe')) === $farbe ) { echo('class="aktiv"'); } ?> href="<?= url($page->url(), ['params' => array_merge(params(),['farbe' => rawurlencode($farbe)])]) ?>">
  <?= html($farbe) ?>
<?php if( param('farbe') === $farbe ) { echo('<a class="closefilter" href="');echo($filteredURL);echo('">×</a>'); } ?>
  <a <?php if(urldecode(param('farbe')) === $farbe ) { echo('class="aktiv"'); } ?> href="<?= url($page->url(), ['params' => ['farbe' => urlencode($farbe)]]) ?>">
  <?= html($farbe) ?>