Get Started
Install Unhead Schema.org
Setup
1. Install the Package
Install @unhead/schema-org in your project:
yarn add @unhead/schema-org
npm install @unhead/schema-org
pnpm add @unhead/schema-org
2. Configure Schema.org Params
At a minimum, provide a host:
<script lang="ts">
import { useHead } from '@unhead/svelte'
useHead({
templateParams: {
schemaOrg: {
host: 'https://example.com',
}
}
})
</script>
See Schema.org Params for all available options.
3. Add Site Schema.org
Import from the Svelte adapter so useSchemaOrg() gets the head instance from Svelte context and registers component cleanup:
<script lang="ts">
import { defineWebPage, defineWebSite, useSchemaOrg } from '@unhead/schema-org/svelte'
useSchemaOrg([
defineWebSite({ name: 'Example Site' }),
defineWebPage(),
])
</script>
Recommended: Vite Plugin
The Vite plugin can tree-shake server-only code and transform head composables at build time:
vite.config.ts
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { Unhead } from '@unhead/svelte/vite'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [svelte(), Unhead()],
})
Optional: Auto-Imports
The Svelte adapter exports an auto-import preset:
vite.config.ts
import { schemaOrgAutoImports } from '@unhead/schema-org/svelte'
import AutoImport from 'unplugin-auto-import/vite'
export default defineConfig({
plugins: [
AutoImport({
imports: schemaOrgAutoImports,
}),
],
})
Next Steps
- Choose an Identity
- Set up your pages with Schema.org Params
- Follow a recipe:
Did this page help you?