I’m migrating from Wordpress to Hugo.
So I have some questions about categories.
I searched several times, but I couldn’t solve it, so let me ask you a question.
First, how do I change the category slug?
For example, I would like to be able to access the category “diary” with “d”.
Then is there a way to change the “/categories” in the category URL to something like “/category”?
I would appreciate it if you could let me know.
Yes, that’s possible. All you need to do is create a folder with the category name in your
So, your example could look like:
content/categories/diary/. In that, create a
_index.md file and in it, specify the URL like:
If you want it like,
/category/d/, you can also use
slug instead of
That’s possible too.
config.toml, specify it like this:
I tried the following, but there seems to be a slight problem.
- Create “content/categories/diary/_index.md”
- Add the following to “config.toml”.
categories = "/category/:slug/"
Then I generated an HTML file.
However, a folder for each category is created in the “category” folder, and “index.html” is created in the “categories” folder.
How can I make this so that “index.html” is also created in the “category” folder?
I said, the
config.toml should have this:
Notice the singular category being used it. That’s what’s defining the slug for categories. The way you have entered, that is:
it’s anyways the default behaviour. and need not be declared.
It seems wrong when I copied it to the post.
So does it still not work when you use ‘category’ in config?
No, I changed it in the settings and it works.
However, I am in trouble because the structure of the folder is as follows.
I want to change this to the following folder structure.
Is this possible?
I think, you can create another file here:
content/categories/_index.md and set the frontmatter:
This should do it. However, it should have worked by just using the config. Nevertheless, the method mentioned now would mostly fix it all.
The method you taught me worked.
Thank you very much.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.