Table of Contents
head-core
Note: The options API is still evolving; expect tweaks as the project grows.
What it does
head-core injects <head> elements — canonical, meta, Open Graph, Twitter, links, and scripts — into any template that contains a <baseline-head> tag. It merges site-wide defaults from _data/head.js with per-page front matter, then replaces the tag with the rendered elements via PostHTML.
Defaults
- Head tag:
<baseline-head>— the marker that gets replaced. - Data key:
head— the front matter key for per-page overrides. - Canonical: built from
page.url, absolutized withsite.url(orURL/DEPLOY_URLenv vars) +pathPrefix. Override per page withhead.canonical. - Robots: omitted unless
noindex: trueis set in front matter (emitsnoindex, nofollow). - OG/Twitter: site-wide defaults from
_data/head.js; per-page overrides viahead.openGraph/head.twitter.
Options
| Option | Type | Default | Description |
|---|---|---|---|
verbose |
boolean | Baseline verbose |
Extra logging from the head builder. |
Other head-core options are internal for now.
How it works
-
Content map caching.
On the
eleventy.contentMapevent, head-core builds an inputPath↔url lookup. This powers canonical resolution — even when a page doesn’t have an explicit URL in its data. -
Computed head data.
Adds
eleventyComputed.page.head, which calls a sharedbuildHeadfunction. This merges site data,_data/head.js, and page-levelhead:front matter into a single object per page. -
HTML transform.
A PostHTML plugin finds
<baseline-head>and replaces it with the rendered elements. It reusespage.headwhen available (from step 2), or callsbuildHeaddirectly. Element order is preserved: base meta, title, canonical link, links/scripts, then OG/Twitter meta.
Tips
<baseline-head>must be inside<head>. If it’s missing, no elements are injected — no error, just silence.- Set global defaults in
_data/head.js; override per page withhead:in front matter. Page-level values win. - For absolute canonicals and
og:url, setsite.urlin your data or useURL/DEPLOY_URLenv vars. Without a URL, canonicals will be relative. noindex: truein front matter emits a robots meta tag and excludes the page from the sitemap (via sitemap-core).- See Head & SEO Basics for a guided setup, Deployment URL Checks for URL hygiene, and Custom Social Previews for OG/Twitter customization.
Peer deps
None — uses PostHTML bundled with Eleventy.
Previous: assets-postcss
Next: multilang-core