Add tags to your Sanity IO articles

Add tags to your Sanity IO articles

Learn how to add tags to your Sanity IO articles using autocomplete-tags.

Sanity has an official plugin that allows you to add tags to your posts and provides features like autocomplete and predefine tags.

Setting up our project

First, we will install the required plugin and add implement it to our document.

Install required packages

Navigate to your sanity project directory and install the plugin by running the following command

sanity install autocomplete-tags

Implementation

Wherever you want to add tags to an item in your schema, just add the following snippet

{
  name: 'tags',
  title: 'Tags',
  type: 'tags',
  options: {
    frozen: true,
    preload: [{label: "NextJS", value: "NextJS"}, {label: "TailWind", value: "TailWind"}],
    closeMenuOnSelect: true
  }
}

Define your tag names and values in the preload array

That,s it restart your sanity server and now you can add tags to your articles

All at a glance

code-snapshot.png