WebSiteSchema
Outputs a WebSite with the site name and URL, optionally with a SearchAction, once on the home page or in the base layout.
WebSiteSchema produces a WebSite: the name and URL of the site
as a whole. Google uses the site name for the name shown next to search results; see Google:
Site names. With
searchQueryInput it adds a SearchAction that describes
the site’s search URL, the markup Google used for the Sitelinks search box. Google has retired
that search box (Google Search updates);
the SearchAction remains valid schema.org markup.
Place it once, on the home page or in the base layout. For a single page, use
WebPageSchema.
Example
---
// src/pages/index.astro
import Layout from '../layouts/Layout.astro';
import { WebSiteSchema } from '@casoon/astro-structured-data/components';
---
<Layout title="Example">
<WebSiteSchema name="Example" searchQueryInput="q" />
</Layout>
The site’s search must accept the term in the given query parameter, here
https://example.com/?q=astro.
Output
With siteUrl: 'https://example.com':
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "Example",
"url": "https://example.com",
"potentialAction": {
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "https://example.com/?q={search_term_string}"
},
"query-input": "required name=q"
}
}
Without searchQueryInput, only @type, name and url are output.
Props
| Prop | Type | Required | Default/fallback | Description |
|---|---|---|---|---|
name |
string |
Yes | – | Name of the site. |
url |
string (absolute http(s) URL) |
No | siteUrl |
URL of the site. Also the base of the search URL template. |
id |
string |
No | – | Output as @id, e.g. https://example.com/#website, so other items can reference the site. |
searchQueryInput |
string |
No | – | Name of the query parameter of the site search, e.g. q. Adds the SearchAction. |
changefreq |
'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never' |
No | – | Sitemap hint, see Sitemap hints. |
priority |
number (0–1) |
No | – | Sitemap hint. |
Rules
urlmust be an absolutehttp(s)URL. Without it,siteUrlis used exactly as configured.searchQueryInputmay only contain letters, digits,_and-(“Must be a query parameter name like “q”“). The search URL is built as<url without trailing slash>/?<param>={search_term_string}, so the search has to live at the root of the site.- WebSite has no recommended fields.
Meta tags
With generateMeta: true, WebSite is the last choice for the primary schema: it drives the
meta tags only when no more specific schema (Article, Product, WebPage, …) is on the page. Then
its name becomes og:title and twitter:title. A WebSiteSchema in the base layout
therefore never overrides the tags of the individual pages. See Meta tags and sitemap
hints.