Streamlining Jekyll Content with Front Matter Defaults
Why Front Matter Defaults Are Game-Changing in Jekyll
One of the most tedious parts of managing a growing Jekyll site is the repetitive front matter in every file. Whether you’re writing blog posts, documentation, or product listings, you often find yourself copying the same values like layout, author, category, and permalink again and again. This repetition clutters your files and introduces a greater risk of inconsistencies.
Jekyll’s front matter defaults provide an elegant solution. Introduced in Jekyll 3, this feature allows you to define shared front matter properties based on path or type—meaning you can automatically apply values to entire directories of content without repeating them in every file.
What Are Front Matter Defaults?
Front matter defaults are defined in your Jekyll site’s _config.yml file under the defaults key. They let you assign specific front matter properties to:
- Files in certain folders
- Files with specific front matter types (e.g.,
posts,pages) - Files matching a combination of scope filters (like path and type)
They’re especially useful when your project has a consistent content model, such as documentation sections, blog posts, or localized pages.
Basic Syntax and Structure
Here’s how front matter defaults are structured in your _config.yml:
defaults:
- scope:
path: "docs"
type: "pages"
values:
layout: "doc"
author: "admin"
category: "documentation"
Every file in the docs folder (with type pages) will now use the doc layout, have the author set to "admin", and be categorized as "documentation"—without needing to include those keys in each file’s front matter.
Practical Use Case: Streamlining Documentation
Let’s imagine you run a product documentation site on GitHub Pages, structured like this:
docs/
getting-started.md
features.md
api.md
Originally, each file looks like this:
---
layout: doc
author: admin
category: documentation
---
Now, update your _config.yml:
defaults:
- scope:
path: "docs"
values:
layout: "doc"
author: "admin"
category: "documentation"
With that in place, your files can be reduced to:
---
title: Getting Started
---
It’s cleaner, less error-prone, and much easier to scale.
Using Type-Based Defaults
Jekyll recognizes certain content types out of the box:
posts– Files in_posts/pages– Files in the root or any non-underscored folderdrafts– Files in_drafts/collections– Custom collections defined in_config.yml
You can assign default values per type. Example:
defaults:
- scope:
type: "posts"
values:
layout: "post"
author: "editor"
This ensures all blog posts share the same layout and author metadata unless overridden individually.
Advanced Use Case: Localized Content
Suppose your site supports multiple languages and has this structure:
docs/
en/
intro.md
fr/
intro.md
You want to apply different layouts or metadata based on language. Here’s how you’d use scoped defaults:
defaults:
- scope:
path: "docs/en"
values:
lang: "en"
layout: "doc"
- scope:
path: "docs/fr"
values:
lang: "fr"
layout: "doc-fr"
This way, you don’t need to manually include lang in every translated file, and each version can use language-specific layouts for localization or RTL support.
Combining With Includes and Layouts
Front matter defaults work beautifully alongside includes and modular layouts. You can predefine common properties and let the includes adapt behavior accordingly. For example:
_includes/lang-banner.html
{% raw %}{% if page.lang == "fr" %}<p>Contenu en français</p>{% elsif page.lang == "en" %}<p>Content in English</p>{% endif %}{% endraw %}
With a default lang value in _config.yml, this include automatically reflects the right language banner across the site.
Case Study: Migrating 200 Blog Posts
In a large content migration from WordPress to Jekyll, a team imported over 200 blog posts into the _posts directory. Initially, every Markdown file included this front matter:
---
layout: post
author: default-author
category: blog
---
By applying front matter defaults for posts type in _config.yml, they removed all three redundant fields and reduced file size across the board. Not only did this cut down clutter, it made the repo more readable and simplified onboarding for new contributors.
Tips for Managing Front Matter Defaults
- Organize your
defaultsby scope, and use comments in_config.ymlto label them - Always test the result in development using
jekyll serveto ensure the values apply correctly - Use
jekyll build --verboseto inspect how defaults are applied - Avoid deeply nested scopes unless necessary, as specificity can cause confusion
Limitations and Gotchas
While front matter defaults are powerful, there are caveats:
- They don’t apply to includes—only to content files like pages, posts, and collections
- Defaults cannot contain Liquid templating—they are static values
- If a file manually defines a key (like
layout), it overrides the default
Understanding this hierarchy is key to using defaults effectively without unintended overrides.
Future-Proofing Large Sites
If you run a long-lived project—like a blog, digital archive, or wiki-style documentation—front matter defaults let you evolve your site architecture without rewriting existing files. You can change layouts, adjust authorship, or switch categories globally from one file: _config.yml.
Example: Changing Layouts for an Entire Section
Imagine you rebranded your docs and introduced a new layout. Instead of editing 300 Markdown files, you just update:
defaults:
- scope:
path: "docs"
values:
layout: "new-doc"
This alone makes defaults an essential tool in any scalable Jekyll workflow.
Conclusion
Jekyll’s front matter defaults offer a cleaner, faster, and more maintainable way to manage content metadata. They empower you to eliminate redundancy, enforce consistency, and adapt your site structure with ease. When combined with includes, layouts, and collections, they unlock a modular, DRY architecture ideal for long-term projects on GitHub Pages.
In the next article, we’ll build on this by exploring how to leverage Jekyll collections to organize and query structured content like tutorials, team members, or changelogs in an elegant way.
