Index of every page on this site: llms.txt
TypeScript
Get Started

Install Unhead Schema.org

Setup

1. Install the Package

Install @unhead/schema-org in your project:

yarn add @unhead/schema-org

2. Configure the Plugin

At a minimum, provide a host when creating the head instance:

import { UnheadSchemaOrg } from '@unhead/schema-org'
import { createHead } from 'unhead/client'

const head = createHead({
  plugins: [
    UnheadSchemaOrg({ host: 'https://example.com' }),
  ]
})

Use createHead() from unhead/server for SSR. See Schema.org Params for all available options.

3. Add Site Schema.org

The framework-agnostic useSchemaOrg() function takes the head instance as its first argument:

import { defineWebPage, defineWebSite, useSchemaOrg } from '@unhead/schema-org'

const schemaEntry = useSchemaOrg(head, [
  defineWebSite({ name: 'Example Site' }),
  defineWebPage(),
])

Call schemaEntry.patch() to update the nodes and schemaEntry.dispose() when their scope ends.

With Vite, the Unhead plugin can tree-shake server-only code and transform head composables at build time.

Optional: Auto-Imports

schemaAutoImports lists the exported Schema.org helper names for tools such as unplugin-auto-import:

vite.config.ts
import { schemaAutoImports } from '@unhead/schema-org/imports'
import AutoImport from 'unplugin-auto-import/vite'

export default defineConfig({
  plugins: [
    AutoImport({
      imports: [
        {
          '@unhead/schema-org': schemaAutoImports,
        },
      ],
    }),
  ],
})

Auto-importing does not supply the required head argument to useSchemaOrg().

Next Steps

  1. Choose an Identity
  2. Set up your pages with Schema.org Params
  3. Follow a recipe:
Did this page help you?