How to add/remove categories

How to add/remove categories

Theme Usage
How to add/remove categories

Categories are a crucial part of organizing your content and helping users navigate your site. This post will guide you through the process of editing categories in your theme, using the categories.ts file.

Understanding the categories.ts File

The categories.ts file is where your theme’s categories are defined. It’s a TypeScript file that exports an array of category objects. Each object typically includes:

Here’s an example of what a category object looks like:

export const categories = [
  { name: 'Category 1', slug: 'category-1', description: 'Description of Category 1' },
  { name: 'Category 2', slug: 'category-2', description: 'Description of Category 2' },
];

Modifying a Category

  1. Open the categories.ts file.
  2. Find the category you want to modify and change its name, slug, or description properties.

For example, to update the description of the “Tech” category:

export const categories = [
  { name: 'Tech', slug: 'tech', description: 'All things tech-related' },
  { name: 'Design', slug: 'design', description: 'Design tips and tutorials' },
];

Adding a New Category

  1. Open the categories.ts file.
  2. Add a new object to the array with the desired name, slug, and description.

For example, to add a new category called “Marketing”:

export const categories = [
  ...existingCategories,
  { name: 'Marketing', slug: 'marketing', description: 'Marketing tips and tutorials' },
];