Custom Nodes
Create custom Schema.org nodes by passing a plain object to useSchemaOrg(). Set @type to the schema type and add any valid Schema.org properties.
Why Create Custom Schema.org Nodes?
Use a custom node when Unhead does not provide a dedicated helper for the Schema.org type you need.
Custom nodes are plain objects following the Schema.org specification.
import { useSchemaOrg } from '@unhead/schema-org'
useSchemaOrg(unheadInstance, [
{
'@type': 'SingleFamilyResidence',
'numberOfRooms': 3,
'occupancy': {
'@type': 'QuantitativeValue',
'maxValue': 5,
'unitCode': 'C62',
},
'numberOfBathroomsTotal': 2,
'floorSize': {
'@type': 'QuantitativeValue',
'value': 2000,
'unitCode': 'FTK',
},
'petsAllowed': true,
}
])
Schema.org expects QuantitativeValue objects for measurements such as occupancy and floorSize. Keeping the value and unit together makes the JSON-LD unambiguous.
How Do I Add TypeScript Support for Custom Nodes?
Use schema-dts for full TypeScript support with custom nodes.
import type { DefinedTerm } from 'schema-dts'
import { useSchemaOrg } from '@unhead/schema-org'
useSchemaOrg([
<DefinedTerm> {
'@type': 'DefinedTerm',
'name': 'Unhead Schema.org',
'description': 'Unhead Schema.org is a library for adding Schema.org to your application.',
'inDefinedTermSet': {
'@type': 'DefinedTermSet',
'name': 'Schema.org Libraries',
},
}
])
Related Recipes
- Setting Up Your Identity: Define your organization/person
- Blog Posts: Article structured data
- E-commerce: Product structured data
Schema.org Params
Configure shared Schema.org metadata with host, path, inLanguage, currency, and trailingSlash. Each resolver inherits the values it supports.
Choosing a Schema.org Identity
Set up Organization, Person, or LocalBusiness as your site identity and connect it to articles, products, pages, and your website.