Schema.org Metatag Token Types
Schema.org Metatag adds structured data to your site so search engines and AI assistants can understand what each page is about. Part of that is saying what kind of thing the page describes. A vet clinic, a hotel, a school.
You choose that from a dropdown built out of the Schema.org type tree, which is thousands of entries deep.
For most sites that is fine. You set it once for the content type and you are done, because every page really is the same kind of thing.
It falls apart on a directory. A groomer is not a vet, and a vet is not a hotel, so no single answer is right for all of them. You can add a Metatag field to the content type and let somebody override the type per listing, and that does work, but it means a human hunting through the Schema.org tree every time a listing is added. On a directory of any size that is not realistic, and it goes wrong quietly when somebody picks the nearest thing rather than the right thing.
This module lets that field take a token, so the type comes from your own data instead of from somebody's memory.
Features
- Turns top-level Schema.org type fields from a dropdown into a text field that accepts a token.
- The full Schema.org type list is still there as you type, so choosing a fixed type works exactly as it did.
- The type can be maintained once per category, rather than chosen again on every listing.
- No hunting through the Schema.org tree per item, and no drift as content is added by different people.
- Nothing changes on the output side. Metatag already swaps tokens for real values before a page renders.
Post-Installation
There is no configuration screen and nothing to switch on.
Once enabled, the affected Schema.org Metatag fields appear as text fields with Schema.org suggestions. Edit them where you already edit your Metatag settings, either the Metatag defaults or the Metatag fields on a piece of content, and enter either a Schema.org type or a token.
A worked example. Add a plain text field to your category vocabulary called field_schema_type and give each category its Schema.org type. Then set additionalType to:
[node:field_category:entity:field_schema_type]Every listing now declares its own type, and you maintain the list once per category instead of once per page.
Additional Requirements
- Drupal 10 or 11
- Schema.org Metatag 3.x, which itself requires Metatag
Recommended modules/libraries
- Token, for browsing the tokens available on your content
Similar projects
There is no other module doing this. The Schema.org Metatag and Metatag issue queues have an old request for the additionalType tag itself, and one asking about schemas per content type, but nothing asking for token support on the type selects.
There is a manual way to get the same result. Adding a Metatag field to a content type lets each piece of content override its schema group, including the type. That works, and for a handful of pages it may be all you need.
The difference is where the answer lives. Doing it by hand means somebody picks from the whole Schema.org tree on every single page. This module lets the type come from your own data, so it is maintained once per category rather than once per page, and it cannot drift as content is added.
Things worth knowing
- Only top-level type fields change. Nested type fields inside more complex Schema.org Metatag properties are left alone.
- An empty token removes the property. If a token does not resolve, the property is left out rather than rendered blank. For the main type field that produces incomplete structured data, so either leave a fixed type in the field or use Metatag's fallback chain,
[node:field_one|node:field_two]. - A field with several values uses the first one. Content in three categories takes the type of the first.
- Uninstalling is safe. The fields go back to being dropdowns. Fixed types are still selected. Anything that was a token no longer matches an option, so re-save those fields before relying on them.