How to create URLs that include post tag

Hi, I’m new-ish to Ghost, and despite Googling my problem and reading up on routing, I can’t figure out what should be a pretty simple and common task, so I must be missing something. Help is appreciated.

Right now, my posts are publishing like:
site.com/{slug}

I would like to change this so the permalink includes the name of a tag—for the sake of this example, let’s say the tag I want is report.

I edited the routes.yaml file to include this, but unfortunately my change does not work. The URLs remain the same as before. What am I doing wrong? Thank you.

routes:

collections:
  /:
    permalink: /{slug}/
    template: index
  /report/:
    permalink: /report/{slug}/
    filter: tag:hash-report
  /blog/:
    permalink: /blog/{slug}/

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

There’s a couple things:

  1. Since your / collection doesn’t have a filter, it’s consuming all the posts, meaning the /report/ and /blog/ collections are never used.
  2. If you want your posts to have the primary tag in the permalink, you can use the primary_tag dynamic variable: permalink: /{primary_tag}/{slug}/

For reference, here’s the dynamic routing documentation:

And here’s the specific section that discusses the properties + dynamic variables:

1 Like

@vikaspotluri123 Thank you! I used the primary_tag dynamic variable as you recommended, and it worked.

1 Like