# Replace space in category with - instead

**URL:** https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081
**Category:** Help
**Created:** [May 26, 2021, 7:18am UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081 "2021-05-26T07:18:25Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![fz22gq](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/fz22gq/32/3607_2.png) [@fz22gq](https://talk.jekyllrb.com/u/fz22gq)
#### Post date: [May 26, 2021, 7:18am UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/1 "2021-05-26T07:18:25Z")

</div>

This relates to the url created for a new blog post when the category has multiple words.

I want to either remove the category “How-to Guides” or replace the space with “-” instead of “%20” as per this example (full url removed so it’s not hyperlinked) … /how-to%20guides/2021/05/24/configuring-metamask-for-coston-testnet.html

I have some permalink settings defined in the \_config.yml …

```
permalinks:
    category: /blog/:slugified_categories/:name/
    tag: /blog/tags/:name/
    permalink: /:slugified_categories/:year/:month/:day/:title:output_ext

```

But they seem to be overridden by the seo.html. Any changes to the above take no effect.

```
{% if page.canonical_url %}
  {%- assign canonical_url = page.canonical_url %}
{% else %}
  {%- assign canonical_url = page.url | replace: "index.html", "" | absolute_url %}
{% endif %}

```

Then …

```
<meta property="og:url" content="{{ canonical_url }}">

```

Any suggestions on how best to do this please?

---

<div class="post-metadata">

### Author: ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)
#### Post date: [May 26, 2021, 8:55am UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/2 "2021-05-26T08:55:18Z")

</div>

I’d say stay with hyphens. Search engines understand them as breaks between words. Underscores are bad here

And %20 is not readable. Some browsers show as a space and some as %20

The Jekyll style is use hyphens and lower case for categories so I’d say don’t that. If you need friendly names for your categories like My Category as a heading and my-category as a label, then that’s worth doing but keep them separate.

---

<div class="post-metadata">

### Author: ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)
#### Post date: [May 26, 2021, 8:57am UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/3 "2021-05-26T08:57:54Z")

</div>

Please put your code in triple backticks or indent by 4 spaces to make it a code block.

I think you meant to indent your config to have values under permalink? I don’t know the significance of that. You can set `permalink` (no plural) as a string in frontmatter, config top level and within categories in config.

Jekyll won’t recognize or process `permalinks`.

And you are gonna want to use `:categories` and not slugified categories in the URL.

> **[Permalinks](https://michaelcurrin.github.io/dev-cheatsheets/cheatsheets/jekyll/templating/permalinks.html)**
>
> A collection of code snippets and CLI guides for quick and easy reference while coding

---

<div class="post-metadata">

### Author: ![fz22gq](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/fz22gq/32/3607_2.png) [@fz22gq](https://talk.jekyllrb.com/u/fz22gq)
#### Post date: [May 26, 2021, 10:06am UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/4 "2021-05-26T10:06:36Z")

</div>

My apologies, I’ve put the code indented now.

I’ve adjusted the permalink as follows; still no change.

```
permalink:
category: /blog/:categories/:name/
tag: /blog/tags/:name/
permalink: /:categories/:year/:month/:day/:title:output_ext

```

Your previous post, agreed I want hyphens only, no space and no %20.

I’m happy to remove the category altogether to resolve this … Thanks for the dev cheatsheets.

It seems to be using the Open Graph settings in the set.html file and not reading the permalink?

---

<div class="post-metadata">

### Author: ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)
#### Post date: [May 26, 2021, 12:30pm UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/5 "2021-05-26T12:30:36Z")

</div>

> [@fz22gq](#):
>
> ```auto
> permalinks:
> category: /blog/:slugified_categories/:name/
> tag: /blog/tags/:name/
> permalink: /:slugified_categories/:year/:month/:day/:title:output_ext
> 
> ```

Again, this is not valid in Jekyll. Where does permalinks with the data in it come from - a plugin or your code?

Keep things simple. I’d say **don’t** even set permalink at all in your config. You will **already** get category and date appearing in the URL.

And add categories like this in your post.

```auto
---
title: My title
categories: abc,def-xyz
---

```

Lowercase and with hyphens.

Result:

```auto
_site/abc/def-xyz/2021/02/03/my-post.html

```

You can list all categories (and tags) on your homepage or a categories page if you want.

---

<div class="post-metadata">

### Author: ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)
#### Post date: [May 26, 2021, 12:33pm UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/6 "2021-05-26T12:33:52Z")

</div>

> [@fz22gq](#):
>
> But they seem to be overridden by the seo.html. Any changes to the above take no effect.

Your seo bit will not change the URLs of how pages get outputted. It will only add metadata like title and canonical URL and insert it in your head tag.

The SEO bit I think is unrelated. Get your site to work using no permalink and some sensible category definitions. Turn SEO file off if you must. Then once your URLs are figured out, you can look at the SEO metadata that gets generated. I’d also recommend the Jekyll SEO plugin so you don’t have to manage seo.html yourself in every site of yours.

---

<div class="post-metadata">

### Author: ![fz22gq](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/fz22gq/32/3607_2.png) [@fz22gq](https://talk.jekyllrb.com/u/fz22gq)
#### Post date: [May 27, 2021, 1:10am UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/7 "2021-05-27T01:10:35Z")

</div>

I removed the permalink from config and there was no change. I’ve just edited the category names to include a hyphen which means categories listed as “Flare-Network” which doesn’t look nice so I’ve removed that.

A workaround yes. I appreciate your assistance.

---

<div class="post-metadata">

### Author: ![Zentor](https://avatars.discourse-cdn.com/v4/letter/z/a8b319/32.png) [@Zentor](https://talk.jekyllrb.com/u/Zentor)
#### Post date: [July 5, 2022, 5:55am UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/8 "2022-07-05T05:55:30Z")

</div>

Hello,

If someone has the solution to replace space in category URL by hyphen, I take it too 🙂

Thanks

Zentor

---

<div class="post-metadata">

### Author: ![BillRaymond](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/billraymond/32/5963_2.png) [@BillRaymond](https://talk.jekyllrb.com/u/BillRaymond)
#### Post date: [July 5, 2022, 7:37pm UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/9 "2022-07-05T19:37:05Z")

</div>

Look into using the `replace` filter.

For example:

```auto
{%- assign myUrl = "https://hello there world.com/index.com -%}
URL without spaces: {{- myUrl | replace: " ","" -}}

```

output: `https://hellothereworld.com/index.com`

Of course you could replace the text with anything, like dashes, underscores, etc.

---

<div class="post-metadata">

### Author: ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)
#### Post date: [July 5, 2022, 8:16pm UTC](https://talk.jekyllrb.com/t/replace-space-in-category-with-instead/6081/10 "2022-07-05T20:16:06Z")

</div>

I don’t think you can do anything about it as far as the permalink with the category name in it is concerned. There is an old issue about this in the repo where I asked about it and they said at the time that they couldn’t slugify the category name in urls as it would not be backwards compatible.

Someone had a clever work around for it using a data file and then you would make the actual category have a dash in it but then make an entry in a datafile with the space, then where ever you used the category you would check the datafile for the cat name with the space.

I just ended up putting dashes in my cat names.
